/**
  * Generates the dropdown menu.
  * 
  * @return string the rendering result.
  */
 protected function renderDropdown()
 {
     $buttons = [];
     foreach ($this->buttons as $key => $button) {
         $options = $this->options;
         unset($options['id']);
         $url = $this->createUrl($this->key, $key);
         $label = $this->encodeLabels ? Html::encode($button['label']) : $button['label'];
         $buttons[] = ['label' => isset($button['icon']) ? Html::icon($button['icon'], ['class' => 'text-' . $button['type']]) . ' ' . $label : $label, 'url' => $url, 'linkOptions' => $options];
     }
     if (count($buttons) <= 1) {
         return '';
     }
     $splitButton = Button::widget(['label' => '<span class="caret"></span>', 'encodeLabel' => false, 'options' => ['data-toggle' => 'dropdown', 'aria-haspopup' => 'true', 'class' => 'btn-default dropdown-toggle btn-xs']]);
     return $splitButton . "\n" . Dropdown::widget(['items' => $buttons, 'encodeLabels' => false, 'options' => ['class' => 'pull-right']]);
 }
Ejemplo n.º 2
0
 /**
  * Initializes the default button rendering callbacks.
  */
 public function initDefaultButtons()
 {
     if (!isset($this->buttons['view'])) {
         $this->buttons['view'] = function ($url, $model, $key) {
             return Html::a(Html::icon('eye', ['class' => 'text-warning']) . ' ' . Yii::t($this->_messageCategory, 'View'), $url, ['data-pjax' => '0']);
         };
     }
     if (!isset($this->buttons['update'])) {
         $this->buttons['update'] = function ($url, $model, $key) {
             return Html::a(Html::icon('pencil', ['class' => 'text-success']) . ' ' . Yii::t($this->_messageCategory, 'Edit'), $url, ['data-pjax' => '0']);
         };
     }
     if (!isset($this->buttons['delete'])) {
         $this->buttons['delete'] = function ($url, $model, $key) {
             return Html::a(Html::icon('times', ['class' => 'text-danger']) . ' ' . Yii::t($this->_messageCategory, 'Delete'), $url, ['data-confirm' => $this->deleteMessage, 'data-method' => 'post', 'data-pjax' => '0']);
         };
     }
 }