123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace yii\bootstrap;
- use yii\helpers\ArrayHelper;
- class ButtonGroup extends Widget
- {
-
- public $buttons = [];
-
- public $encodeLabels = true;
-
- public function init()
- {
- parent::init();
- Html::addCssClass($this->options, ['widget' => 'btn-group']);
- }
-
- public function run()
- {
- BootstrapAsset::register($this->getView());
- return Html::tag('div', $this->renderButtons(), $this->options);
- }
-
- protected function renderButtons()
- {
- $buttons = [];
- foreach ($this->buttons as $button) {
- if (is_array($button)) {
- $visible = ArrayHelper::remove($button, 'visible', true);
- if ($visible === false) {
- continue;
- }
- $button['view'] = $this->getView();
- if (!isset($button['encodeLabel'])) {
- $button['encodeLabel'] = $this->encodeLabels;
- }
- $buttons[] = Button::widget($button);
- } else {
- $buttons[] = $button;
- }
- }
- return implode("\n", $buttons);
- }
- }
|