/**
  * Initializes the default button rendering callbacks
  */
 protected function initDefaultButtons()
 {
     if (!isset($this->buttons['view'])) {
         $this->buttons['view'] = function ($url, $model) {
             return Html::a(Html::icon('eye'), $url, ['title' => Yii::t('yii', 'View'), 'data-pjax' => '0']);
         };
     }
     if (!isset($this->buttons['update'])) {
         $this->buttons['update'] = function ($url, $model) {
             return Html::a(Html::icon('pencil'), $url, ['title' => Yii::t('yii', 'Update'), 'data-pjax' => '0']);
         };
     }
     if (!isset($this->buttons['delete'])) {
         $this->buttons['delete'] = function ($url, $model) {
             return Html::a(Html::icon('trash'), $url, ['title' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0']);
         };
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * @return type
  */
 public function renderItems()
 {
     $out = [];
     foreach ($this->items as $i => $item) {
         if (!empty($item['label'])) {
             $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
             $label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
             $label = Html::tag('label', $label);
         } else {
             $label = '';
         }
         $options = ArrayHelper::getValue($item, 'options', []);
         $url = ArrayHelper::getValue($item, 'url', '#');
         if (isset($item['icon'])) {
             if (is_array($item['icon'])) {
                 $iconOptions = ArrayHelper::getValue($item['icon'], 'options', []);
                 $iconPrefix = ArrayHelper::getValue($item['icon'], 'prefix', 'fi-');
                 $iconTag = ArrayHelper::getValue($item['icon'], 'tag', 'i');
                 $icon = Html::icon($item['icon']['name'], $iconOptions, $iconPrefix, $iconTag);
             } else {
                 $icon = Html::icon($item['icon']);
             }
         } elseif (isset($item['img'])) {
             $icon = Html::img($item['img']);
         } else {
             throw new InvalidConfigException("'icon' or 'img' must be set");
         }
         Html::addCssClass($options, 'item');
         $options['role'] = 'button';
         $options['tabindex'] = 0;
         $out[] = Html::a($icon . $label, $url, $options);
     }
     return $out;
 }