TbButtonColumn::initDefaultButtons PHP Method

initDefaultButtons() protected method

Initializes the default buttons (view, update and delete).
protected initDefaultButtons ( )
    protected function initDefaultButtons()
    {
        parent::initDefaultButtons();
        if ($this->viewButtonIcon !== false && !isset($this->buttons['view']['icon'])) {
            $this->buttons['view']['icon'] = $this->viewButtonIcon;
        }
        if ($this->updateButtonIcon !== false && !isset($this->buttons['update']['icon'])) {
            $this->buttons['update']['icon'] = $this->updateButtonIcon;
        }
        if ($this->deleteButtonIcon !== false && !isset($this->buttons['delete']['icon'])) {
            $this->buttons['delete']['icon'] = $this->deleteButtonIcon;
        }
    }

Usage Example

 protected function initDefaultButtons()
 {
     parent::initDefaultButtons();
     /* Кнопка просмотра на фронте */
     if ($this->frontViewButtonLabel === null) {
         $this->frontViewButtonLabel = Yii::t('zii', 'View');
     }
     $button = array('label' => $this->frontViewButtonLabel, 'url' => $this->frontViewButtonUrl ?: function ($data) {
         try {
             return $data->{$this->frontViewGetUrlMethodName}();
         } catch (\Exception $e) {
             return null;
         }
     }, 'options' => $this->frontViewButtonOptions, 'icon' => $this->frontViewButtonIcon);
     if (isset($this->buttons['front_view'])) {
         $this->buttons['front_view'] = array_merge($button, $this->buttons['front_view']);
     } else {
         /* показывать кнопку только если задали ей свой url, или модель имеет метод для получения url*/
         $button['visible'] = function ($row, $data) {
             // todo: найти нормальный способ узнавания есть ли у модели метод
             try {
                 return $this->frontViewButtonUrl || method_exists($data, $this->frontViewGetUrlMethodName) || (bool) $data->{$this->frontViewGetUrlMethodName}();
             } catch (\Exception $e) {
                 return false;
             }
         };
         $this->buttons['front_view'] = $button;
     }
 }
All Usage Examples Of TbButtonColumn::initDefaultButtons