/** * Initializes the default button rendering callbacks. * This method uses [[Icon|Icon]] to display iconic buttons. */ protected function initDefaultButtons() { if (!isset($this->buttons['view'])) { $this->buttons['view'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'View'), 'aria-label' => Yii::t('yii', 'View'), 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'visibility']), $url, $options); }; } if (!isset($this->buttons['update'])) { $this->buttons['update'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'Update'), 'aria-label' => Yii::t('yii', 'Update'), 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'edit']), $url, $options); }; } if (!isset($this->buttons['delete'])) { $this->buttons['delete'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'Delete'), 'aria-label' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'delete']), $url, $options); }; } }
/** * Renders an icon. * @return ActiveField * @throws \Exception */ public function icon() { if ($this->icon === null) { $this->parts['{icon}'] = ''; return $this; } $this->parts['{icon}'] = Icon::widget(['name' => ArrayHelper::getValue($this->icon, 'name', null), 'position' => 'prefix', 'options' => ArrayHelper::getValue($this->icon, 'options', [])]); return $this; }
/** * Renders an icon. * * @return string the rendered icon * @throws \yii\base\InvalidConfigException if icon name is not specified * * @uses http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#getValue()-detail * @see Icon::run */ protected function renderIcon() { if (!$this->icon) { return ''; } return Icon::widget(['name' => ArrayHelper::getValue($this->icon, 'name', null), 'position' => ArrayHelper::getValue($this->icon, 'position', null), 'options' => ArrayHelper::getValue($this->icon, 'options', [])]); }
/** * Executes the widget. * @return string the result of widget execution to be outputted. * @uses [[Icon]] */ public function run() { $tag = ArrayHelper::remove($this->options, 'tag', 'div'); $html = Html::beginTag($tag, $this->options); if ($this->imageOptions) { $src = ArrayHelper::remove($this->imageOptions, 'src', ''); $html .= Html::img($src, $this->imageOptions); } $html .= $this->encodeContent ? Html::encode($this->content) : $this->content; if ($this->renderIcon) { $html .= Icon::widget(['name' => ArrayHelper::getValue($this->icon, 'name', null), 'position' => ArrayHelper::getValue($this->icon, 'position', ''), 'options' => ArrayHelper::getValue($this->icon, 'options', [])]); } $html .= Html::endTag($tag); return $html; }
/** * Renders an icon. * * @param string $state the name of the icon property. * @return string the rendered icon * * @uses http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#getValue()-detail * @see Icon::run */ protected function renderIcon($state) { $iconProperty = "{$state}Icon"; if (!$this->{$iconProperty}) { return ''; } return Icon::widget(['name' => ArrayHelper::getValue($this->{$iconProperty}, 'name', null), 'position' => ArrayHelper::getValue($this->{$iconProperty}, 'position', null), 'options' => ArrayHelper::getValue($this->{$iconProperty}, 'options', [])]); }