[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Toolbar/Button/ -> HelpButton.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Toolbar\Button;
  11  
  12  use Joomla\CMS\Help\Help;
  13  use Joomla\CMS\Language\Text;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Renders a help popup window button
  21   *
  22   * @method self ref(string $value)
  23   * @method self component(string $value)
  24   * @method self useComponent(bool $value)
  25   * @method self url(string $value)
  26   * @method string getRef()
  27   * @method string getComponent()
  28   * @method bool   getUseComponent()
  29   * @method string getUrl()
  30   *
  31   * @since  3.0
  32   */
  33  class HelpButton extends BasicButton
  34  {
  35      /**
  36       * Prepare options for this button.
  37       *
  38       * @param   array  $options  The options about this button.
  39       *
  40       * @return  void
  41       *
  42       * @since  4.0.0
  43       */
  44      protected function prepareOptions(array &$options)
  45      {
  46          $options['text'] = $options['text'] ?: 'JTOOLBAR_HELP';
  47          $options['icon'] = $options['icon'] ?? 'icon-question';
  48          $options['button_class'] = $options['button_class'] ?? 'btn btn-info';
  49          $options['onclick'] = $options['onclick'] ?? $this->_getCommand();
  50  
  51          parent::prepareOptions($options);
  52      }
  53  
  54      /**
  55       * Fetches the button HTML code.
  56       *
  57       * @param   string   $type       Unused string.
  58       * @param   string   $ref        The name of the help screen (its key reference).
  59       * @param   boolean  $com        Use the help file in the component directory.
  60       * @param   string   $override   Use this URL instead of any other.
  61       * @param   string   $component  Name of component to get Help (null for current component)
  62       *
  63       * @return  string
  64       *
  65       * @since   3.0
  66       *
  67       * @deprecated  5.0 Use render() instead.
  68       */
  69      public function fetchButton($type = 'Help', $ref = '', $com = false, $override = null, $component = null)
  70      {
  71          $this->name('help')
  72              ->ref($ref)
  73              ->useComponent($com)
  74              ->component($component)
  75              ->url($override);
  76  
  77          return $this->renderButton($this->options);
  78      }
  79  
  80      /**
  81       * Get the JavaScript command for the button
  82       *
  83       * @return  string  JavaScript command string
  84       *
  85       * @since   3.0
  86       */
  87      protected function _getCommand()
  88      {
  89          // Get Help URL
  90          $url = Help::createUrl($this->getRef(), $this->getUseComponent(), $this->getUrl(), $this->getComponent());
  91          $url = json_encode(htmlspecialchars($url, ENT_QUOTES), JSON_HEX_APOS);
  92          $url = substr($url, 1, -1);
  93          $cmd = "Joomla.popupWindow('$url', '" . Text::_('JHELP', true) . "', 700, 500, 1)";
  94  
  95          return $cmd;
  96      }
  97  
  98      /**
  99       * Method to configure available option accessors.
 100       *
 101       * @return  array
 102       *
 103       * @since   4.0.0
 104       */
 105      protected static function getAccessors(): array
 106      {
 107          return array_merge(
 108              parent::getAccessors(),
 109              [
 110                  'ref',
 111                  'useComponent',
 112                  'component',
 113                  'url'
 114              ]
 115          );
 116      }
 117  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer