/** * Renders a widget's item. * @param mixed $item the item to render. * @return string the rendering result. * @throws \CException */ public function renderItem($item) { if (is_string($item)) { return $item; } if (!isset($item['label'])) { throw new \CException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $items = ArrayHelper::getValue($item, 'items'); $url = \Yii::app()->createUrl(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); if (ArrayHelper::getValue($item, 'active')) { $this->addCssClass($options, 'active'); } if ($items !== null) { $linkOptions['data-toggle'] = 'dropdown'; $this->addCssClass($options, 'dropdown'); $this->addCssClass($urlOptions, 'dropdown-toggle'); $label .= ' ' . \CHtml::tag('b', array('class' => 'caret'), ''); if (is_array($items)) { $items = Dropdown::widget(array('items' => $items, 'clientOptions' => false)); } } return \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items); }
/** * Renders tab items as specified on [[items]]. * @return string the rendering result. * @throws \CException. */ protected function renderItems() { $headers = array(); $panes = array(); foreach ($this->items as $n => $item) { if (!isset($item['label'])) { throw new \CException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', array())); if (isset($item['items'])) { $label .= ' <b class="caret"></b>'; $this->addCssClass($headerOptions, 'dropdown'); if ($this->renderDropdown($item['items'], $panes)) { $this->addCssClass($headerOptions, 'active'); } $header = \CHtml::link($label, "#", array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown')) . "\n" . Dropdown::widget(array('items' => $item['items'], 'clientOptions' => false)); } elseif (isset($item['content'])) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array())); $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $n); $this->addCssClass($options, 'tab-pane'); if (ArrayHelper::remove($item, 'active')) { $this->addCssClass($options, 'active'); $this->addCssClass($headerOptions, 'active'); } $header = \CHtml::link($label, '#' . $options['id'], array('data-toggle' => 'tab', 'tabindex' => '-1')); $panes[] = \CHtml::tag('div', $options, $item['content']); } else { throw new \CException("Either the 'content' or 'items' option must be set."); } $headers[] = \CHtml::tag('li', $headerOptions, $header); } return \CHtml::tag('ul', $this->options, implode("\n", $headers)) . "\n" . \CHtml::tag('div', array('class' => 'tab-content'), implode("\n", $panes)); }