/** * 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']]); }
/** * Creates a data cell content * * @param \yii\db\ActiveRecord $model the data model * @param mixed $key the key associated with the data model * @param integer $index the current row index * @return string the created cell content */ public function renderDataCellContent($model, $key, $index) { preg_match_all('/\\{([\\w\\-\\/]+)\\}/', $this->template, $matches); $items[] = $this->getPrependContent($model, $key, $index); $items[] = Html::beginTag('div', $this->actionOptions); foreach ($matches[1] as $name) { if (isset($this->buttons[$name])) { $url = $this->createUrl($name, $model, $key, $index); $item = call_user_func($this->buttons[$name], $url, $model, $key, $index); if ($item !== '') { $items[] = Html::tag('span', $item, ['class' => $name]); } } } $items[] = Html::endTag('div'); $items[] = $this->append instanceof Closure ? call_user_func($this->append, $model, $key, $index) : $this->append; return implode("\n", $items); }