Example #1
0
 /**
  * Renders tab items as specified on [[items]].
  * @return string the rendering result.
  * @throws InvalidConfigException.
  */
 protected function renderItems()
 {
     $headers = [];
     $panes = [];
     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', []));
         if (isset($item['items'])) {
             if ($this->styled) {
                 throw new InvalidConfigException("The 'styled' not support dropdown items. Please, set 'styled' to false.");
             }
             $label .= ' <b class="caret"></b>';
             Html::addCssClass($headerOptions, 'dropdown');
             if ($this->renderDropdown($item['items'], $panes)) {
                 Html::addCssClass($headerOptions, 'active');
             }
             $header = Html::a($label, "#", ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown']) . "\n" . Dropdown::widget(['items' => $item['items'], 'clientOptions' => false]);
         } 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');
             }
             $header = Html::a($label, '#' . $options['id'], ['data-toggle' => 'tab']);
             $panes[] = Html::tag('div', $item['content'], $options);
         } else {
             throw new InvalidConfigException("Either the 'content' or 'items' option must be set.");
         }
         $headers[] = Html::tag('li', $header, $headerOptions);
     }
     $headers = Html::tag('ul', implode("\n", $headers), $this->options);
     $panes = Html::tag('div', implode("\n", $panes), ['class' => 'tab-content']);
     return $this->placement == self::PLACEMENT_BELOW ? $panes . "\n" . $headers : $headers . "\n" . $panes;
 }
 /**
  * Renders the dropdown
  * @return string the rendering result
  */
 protected function renderDropdown()
 {
     $config = $this->dropdown;
     $config['clientOptions'] = false;
     return Dropdown::widget($config);
 }
Example #3
0
 /**
  * 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['label']) && !isset($item['icon'])) {
         throw new InvalidConfigException("The 'label' option is required.");
     }
     $type = ArrayHelper::getValue($item, 'type', '');
     $options = ArrayHelper::getValue($item, 'options', []);
     if ($type === 'user') {
         $label = $item['label'];
         Html::addCssClass($options, 'user');
     } else {
         $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
     }
     $icon = ArrayHelper::getValue($item, 'icon', null);
     if ($icon) {
         $label = Html::tag('i', '', ['alt' => $label, 'class' => $icon]);
     }
     $label .= ArrayHelper::getValue($item, 'badge', '');
     $items = ArrayHelper::getValue($item, 'items');
     $url = Url::toRoute(ArrayHelper::getValue($item, 'url', '#'));
     $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
     if (isset($item['active'])) {
         $active = ArrayHelper::remove($item, 'active', false);
     } else {
         $active = $this->isItemActive($item);
     }
     if ($active) {
         Html::addCssClass($options, 'active');
     }
     if ($items !== null) {
         $linkOptions['data-toggle'] = 'dropdown';
         $linkOptions['data-hover'] = 'dropdown';
         $linkOptions['data-close-others'] = 'true';
         Html::addCssClass($options, 'dropdown');
         Html::addCssClass($linkOptions, 'dropdown-toggle');
         if (is_array($items)) {
             $items = Dropdown::widget(['title' => ArrayHelper::getValue($item, 'title', ''), 'more' => ArrayHelper::getValue($item, 'more', []), 'scroller' => ArrayHelper::getValue($item, 'scroller', []), 'items' => $items, 'encodeLabels' => $this->encodeLabels, 'clientOptions' => false, 'options' => $type !== 'user' ? ['class' => 'extended'] : []]);
         }
     }
     return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
 }