yii\bootstrap\Nav::renderItem PHP Метод

renderItem() публичный Метод

Renders a widget's item.
public renderItem ( string | array $item ) : string
$item string | array the item to render.
Результат string the rendering result.
    public function renderItem($item)
    {
        if (is_string($item)) {
            return $item;
        }
        if (!isset($item['label'])) {
            throw new InvalidConfigException("The 'label' option is required.");
        }
        $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
        $label = $encodeLabel ? 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', []);
        if (isset($item['active'])) {
            $active = ArrayHelper::remove($item, 'active', false);
        } else {
            $active = $this->isItemActive($item);
        }
        if (empty($items)) {
            $items = '';
        } else {
            $linkOptions['data-toggle'] = 'dropdown';
            Html::addCssClass($options, ['widget' => 'dropdown']);
            Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle']);
            if ($this->dropDownCaret !== '') {
                $label .= ' ' . $this->dropDownCaret;
            }
            if (is_array($items)) {
                $items = $this->isChildActive($items, $active);
                $items = $this->renderDropdown($items, $item);
            }
        }
        if ($active) {
            Html::addCssClass($options, 'active');
        }
        return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
    }

Usage Example

Пример #1
0
 /**
  * @inheritdoc
  */
 public function renderItem($item)
 {
     if ($this->route === null && Yii::$app->response !== null) {
         $this->route = Yii::$app->response->getRoute();
     }
     if (isset($item['active'])) {
         if (is_callable($item['active'])) {
             $item['active'] = call_user_func($item['active'], $this, $item);
         }
     }
     return parent::renderItem($item);
 }
All Usage Examples Of yii\bootstrap\Nav::renderItem