[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2018 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\Toolbar\ToolbarButton;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * Render dropdown buttons.
  20   *
  21   * @method self toggleSplit(bool $value)
  22   * @method self toggleButtonClass(string $value)
  23   * @method bool getToggleSplit()
  24   * @method string getToggleButtonClass()
  25   *
  26   * @since  4.0.0
  27   */
  28  class DropdownButton extends AbstractGroupButton
  29  {
  30      /**
  31       * Property layout.
  32       *
  33       * @var    string
  34       * @since  4.0.0
  35       */
  36      protected $layout = 'joomla.toolbar.dropdown';
  37  
  38      /**
  39       * Prepare options for this button.
  40       *
  41       * @param   array  $options  The options about this button.
  42       *
  43       * @return  void
  44       *
  45       * @since   4.0.0
  46       * @throws  \Exception
  47       */
  48      protected function prepareOptions(array &$options)
  49      {
  50          parent::prepareOptions($options);
  51  
  52          $childToolbar = $this->getChildToolbar();
  53          $options['hasButtons'] = \count($childToolbar->getItems()) > 0;
  54          $buttons = $childToolbar->getItems();
  55  
  56          if ($options['hasButtons']) {
  57              if ($this->getOption('toggleSplit', true)) {
  58                  /** @var ToolbarButton $button */
  59                  $button = array_shift($buttons);
  60  
  61                  $childToolbar->setItems($buttons);
  62  
  63                  $options['button'] = $button->render();
  64                  $options['caretClass'] = $options['toggleButtonClass'] ?? $button->getButtonClass();
  65                  $options['dropdownItems'] = $childToolbar->render(['is_child' => true]);
  66              } else {
  67                  $options['dropdownItems'] = $childToolbar->render(['is_child' => true]);
  68  
  69                  $button = new BasicButton($this->getName(), $this->getText(), $options);
  70  
  71                  $options['button'] = $button
  72                      ->setParent($this->parent)
  73                      ->buttonClass($button->getButtonClass() . ' dropdown-toggle')
  74                      ->attributes(
  75                          [
  76                              'data-bs-toggle' => 'dropdown',
  77                              'data-bs-target' => '#' . $this->fetchId(),
  78                              'aria-haspopup' => 'true',
  79                              'aria-expanded' => 'false',
  80                          ]
  81                      )
  82                      ->render();
  83              }
  84          }
  85      }
  86  
  87      /**
  88       * Render button HTML.
  89       *
  90       * @param   array  $options  The button options.
  91       *
  92       * @return  string  The button HTML.
  93       *
  94       * @since  4.0.0
  95       */
  96      protected function renderButton(array &$options): string
  97      {
  98          return parent::renderButton($options);
  99      }
 100  
 101      /**
 102       * Get the button CSS Id.
 103       *
 104       * @return  string  Button CSS Id
 105       *
 106       * @since   4.0.0
 107       */
 108      protected function fetchId()
 109      {
 110          return $this->parent->getName() . '-dropdown-' . $this->getName();
 111      }
 112  
 113      /**
 114       * Method to configure available option accessors.
 115       *
 116       * @return  array
 117       *
 118       * @since   4.0.0
 119       */
 120      protected static function getAccessors(): array
 121      {
 122          return array_merge(
 123              parent::getAccessors(),
 124              [
 125                  'toggleSplit',
 126                  'toggleButtonClass',
 127              ]
 128          );
 129      }
 130  }


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