'Action', * 'dropdown' => [ * 'items' => [ * ['label' => 'DropdownA', 'url' => '/'], * ['label' => 'DropdownB', 'url' => '#'], * ], * ], * ]); * ``` * @see http://getbootstrap.com/javascript/#buttons * @see http://getbootstrap.com/components/#btn-dropdowns * @author Antonio Ramirez * @since 2.0 */ class ButtonDropdown extends Widget { /** * @var string the button label */ public $label = 'Button'; /** * @var array the HTML attributes of the button. */ public $options = []; /** * @var array the configuration array for [[Dropdown]]. */ public $dropdown = []; /** * @var boolean whether to display a group of split-styled button group. */ public $split = false; /** * @var string the tag to use to render the button */ public $tagName = 'button'; /** * @var boolean whether the label should be HTML-encoded. */ public $encodeLabel = true; /** * Renders the widget. */ public function run() { echo $this->renderButton() . "\n" . $this->renderDropdown(); $this->registerPlugin('button'); } /** * Generates the button dropdown. * @return string the rendering result. */ protected function renderButton() { Html::addCssClass($this->options, 'btn'); $label = $this->label; if ($this->encodeLabel) { $label = Html::encode($label); } if ($this->split) { $options = $this->options; $this->options['data-toggle'] = 'dropdown'; Html::addCssClass($this->options, 'dropdown-toggle'); $splitButton = Button::widget([ 'label' => '', 'encodeLabel' => false, 'options' => $this->options, 'view' => $this->getView(), ]); } else { $label .= ' '; $options = $this->options; if (!isset($options['href'])) { $options['href'] = '#'; } Html::addCssClass($options, 'dropdown-toggle'); $options['data-toggle'] = 'dropdown'; $splitButton = ''; } return Button::widget([ 'tagName' => $this->tagName, 'label' => $label, 'options' => $options, 'encodeLabel' => false, 'view' => $this->getView(), ]) . "\n" . $splitButton; } /** * Generates the dropdown menu. * @return string the rendering result. */ protected function renderDropdown() { $config = $this->dropdown; $config['clientOptions'] = false; $config['view'] = $this->getView(); return Dropdown::widget($config); } }