/** * Renders a widget's item. * @param string|array $item the item to render. * @return string the rendering result. * @throws InvalidConfigException */ public function renderItem($item) { if (is_string($item)) { return $item; } if (isset($item['content'])) { return Html::tag('li', $item['content'], $item['options']); } if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', []); $items = ArrayHelper::getValue($item, 'items'); $url = ArrayHelper::getValue($item, 'url', '#'); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); $badgeOptions = ArrayHelper::getValue($item, 'badgeOptions', []); if (isset($item['active'])) { $active = ArrayHelper::remove($item, 'active', false); } else { $active = $this->isItemActive($item); } if ($items !== null) { //$linkOptions['data-toggle'] = 'treeview'; Html::addCssClass($options, 'treeview'); //Html::addCssClass($linkOptions, 'treeview-menu'); //$label .= ' ' . Html::tag('i', '', ['class' => 'fa fa-angle-left pull-right']); if (is_array($items)) { if ($this->activateItems) { $items = $this->isChildActive($items, $active); } $items = Dropdown::widget(['items' => $items, 'encodeLabels' => $this->encodeLabels, 'clientOptions' => false, 'type' => Dropdown::NAV, 'view' => $this->getView()]); } } if ($this->activateItems && $active) { Html::addCssClass($options, 'active'); } $label = Html::tag('i', '', $linkOptions) . Html::tag('span', $label); $label .= $this->renderBadge($badgeOptions); if ($items !== null) { $label .= Html::tag('i', '', ['class' => 'fa fa-angle-left pull-right']); } return Html::tag('li', Html::a($label, $url) . $items, $options); }
/** * Renders tab items as specified on [[items]]. * @return string the rendering result. * @throws InvalidConfigException. */ protected function renderItems() { $headers = []; $panes = []; if (!$this->hasActiveTab() && !empty($this->items)) { $this->items[0]['active'] = true; } foreach ($this->items as $n => $item) { if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', [])); $linkOptions = array_merge($this->linkOptions, ArrayHelper::getValue($item, 'linkOptions', [])); if (isset($item['items'])) { $label .= ' <b class="caret"></b>'; Html::addCssClass($headerOptions, 'dropdown'); if ($this->renderDropdown($item['items'], $panes)) { Html::addCssClass($headerOptions, 'active'); } Html::addCssClass($linkOptions, 'dropdown-toggle'); $linkOptions['data-toggle'] = 'dropdown'; $header = Html::a($label, "#", $linkOptions) . "\n" . Dropdown::widget(['items' => $item['items'], 'clientOptions' => false, 'view' => $this->getView()]); } elseif (isset($item['content'])) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $n); Html::addCssClass($options, 'tab-pane'); if (ArrayHelper::remove($item, 'active')) { Html::addCssClass($options, 'active'); Html::addCssClass($headerOptions, 'active'); } $linkOptions['data-toggle'] = 'tab'; $header = Html::a($label, '#' . $options['id'], $linkOptions); $panes[] = Html::tag('div', $item['content'], $options); } else { if (isset($item['nocontent'])) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $n); Html::addCssClass($options, 'tab-pane'); if (ArrayHelper::remove($item, 'active')) { Html::addCssClass($options, 'active'); Html::addCssClass($headerOptions, 'active'); } if (isset($item['header'])) { $header = $item['label']; } else { $header = Html::a($label, '#' . $options['id'], $linkOptions); } } else { throw new InvalidConfigException("Either the 'content' or 'items' option must be set."); } } $headers[] = Html::tag('li', $header, $headerOptions); } return Html::tag('ul', implode("\n", $headers), $this->options) . "\n" . Html::tag('div', implode("\n", $panes), ['class' => 'tab-content']); }
/** * Generates the dropdown menu. * @return string the rendering result. */ protected function renderDropdown() { $config = $this->dropdown; $config['clientOptions'] = false; $config['view'] = $this->getView(); return Dropdown::widget($config); }