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