123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace yii\bootstrap;
- use yii\helpers\Html;
- class ButtonDropdown extends Widget
- {
-
- public $label = 'Button';
-
- public $options = [];
-
- public $dropdown = [];
-
- public $split = false;
-
- public $tagName = 'button';
-
- public $encodeLabel = true;
-
- public function run()
- {
- echo $this->renderButton() . "\n" . $this->renderDropdown();
- $this->registerPlugin('button');
- }
-
- 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' => '<span class="caret"></span>',
- 'encodeLabel' => false,
- 'options' => $this->options,
- 'view' => $this->getView(),
- ]);
- } else {
- $label .= ' <span class="caret"></span>';
- $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;
- }
-
- protected function renderDropdown()
- {
- $config = $this->dropdown;
- $config['clientOptions'] = false;
- $config['view'] = $this->getView();
- return Dropdown::widget($config);
- }
- }
|