protected function renderItems($items, $options = [])
    {
        $lines = [];
        foreach ($items as $item) {
            if (is_string($item)) {
                if ($item === static::DIVIDER) {
                    $lines[] = $this->renderDivider();
                } else {
                    $lines[] = $item;
                }
                continue;
            }
            if (isset($item['visible']) && !$item['visible']) {
                continue;
            }
            if (!array_key_exists('label', $item)) {
                throw new InvalidConfigException("The 'label' option is required.");
            }
            $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
            $label = $encodeLabel ? $this->htmlHlp->encode($item['label']) : $item['label'];
            $itemOptions = ArrayHelper::getValue($item, 'options', []);
            $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
            $itemOptions = ArrayHelper::merge($itemOptions, $linkOptions);
            Html::addCssClass($itemOptions, ['widget' => 'dropdown-item']);
            $url = array_key_exists('url', $item) ? $item['url'] : null;
            if ($url === null) {
                Html::addCssClass($itemOptions, ['widget' => 'dropdown-header']);
                $content = $this->renderHeader($label);
            } else {
                $content = $this->htmlHlp->a($label, $url, $itemOptions);
            }

            $lines[] = $content;
        }

        return $this->htmlHlp->tag('div', implode("\n", $lines), $options);
    }
protected function renderItems($items, $options = [])
    {
        $lines = [];
        foreach ($items as $item) {
            if (is_string($item)) {
                if ($item === static::DIVIDER) {
                    $lines[] = $this->renderDivider();
                } else {
                    $lines[] = $item;
                }
                continue;
            }
            if (isset($item['visible']) && !$item['visible']) {
                continue;
            }
            if (!array_key_exists('label', $item)) {
                throw new InvalidConfigException("The 'label' option is required.");
            }
            $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
            $label = $encodeLabel ? $this->htmlHlp->encode($item['label']) : $item['label'];
            $itemOptions = ArrayHelper::getValue($item, 'options', []);
            $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
            $itemOptions = ArrayHelper::merge($itemOptions, $linkOptions);
            Html::addCssClass($itemOptions, ['widget' => 'dropdown-item']);
            $url = array_key_exists('url', $item) ? $item['url'] : null;
            if ($url === null) {
                Html::addCssClass($itemOptions, ['widget' => 'dropdown-header']);
                $content = $this->renderHeader($label);
            } else {
                $content = $this->htmlHlp->a($label, $url, $itemOptions);
            }

            $lines[] = $content;
        }

        return $this->htmlHlp->tag('div', implode("\n", $lines), $options);
    }
protected function renderItems ( $ items , $ options = [ ] ) { $ lines = [ ] ; foreach ( $ items as $ item ) { if ( is_string ( $ item ) ) { if ( $ item === static :: DIVIDER ) { $ lines [ ] = $ this -> renderDivider ( ) ; } else { $ lines [ ] = $ item ; } continue ; } if ( isset ( $ item [ 'visible' ] ) && ! $ item [ 'visible' ] ) { continue ; } if ( ! array_key_exists ( 'label' , $ item ) ) { throw new InvalidConfigException ( "The 'label' option is required." ) ; } $ encodeLabel = isset ( $ item [ 'encode' ] ) ? $ item [ 'encode' ] : $ this -> encodeLabels ; $ label = $ encodeLabel ? $ this -> htmlHlp -> encode ( $ item [ 'label' ] ) : $ item [ 'label' ] ; $ itemOptions = ArrayHelper :: getValue ( $ item , 'options' , [ ] ) ; $ linkOptions = ArrayHelper :: getValue ( $ item , 'linkOptions' , [ ] ) ; $ itemOptions = ArrayHelper :: merge ( $ itemOptions , $ linkOptions ) ; Html :: addCssClass ( $ itemOptions , [ 'widget' => 'dropdown-item' ] ) ; $ url = array_key_exists ( 'url' , $ item ) ? $ item [ 'url' ] : null ; if ( $ url === null ) { Html :: addCssClass ( $ itemOptions , [ 'widget' => 'dropdown-header' ] ) ; $ content = $ this -> renderHeader ( $ label ) ; } else { $ content = $ this -> htmlHlp -> a ( $ label , $ url , $ itemOptions ) ; } $ lines [ ] = $ content ; } return $ this -> htmlHlp -> tag ( 'div' , implode ( "\n" , $ lines ) , $ options ) ; }
Renders menu items.
@param array $items the menu items to be rendered
@param array $options the container HTML attributes
@return string the rendering result.
@throws InvalidConfigException if the label option is not specified in one of the items.
Renders menu items .