Please note that the Materialize icons are shipped in a separate font file. This font file is automatically registered by the [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]]. If you do not load the default [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]] make sure to at least load [[\macgyer\yii2materializecss\assets\MaterializeFontAsset|MaterializeFontAsset]] (or another source providing the font file) to correctly display the icons.
See also: http://materializecss.com/icons.html
Author: Christoph Erdmann (yii2-materializecss@pluspunkt-coding.de)
Inheritance: extends macgyer\yii2materializecss\lib\BaseWidget
 /**
  * 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;
 }
示例#3
0
 /**
  * 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', [])]);
 }
示例#4
0
 /**
  * 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', [])]);
 }