backend/widgets/Menu.php
/**
     * Recursively renders the menu items (without the container tag).
     * @param array $items the menu items to be rendered recursively
     * @return string the rendering result
     */
Recursively renders the menu items (without the container tag).
@param array $items the menu items to be rendered recursively
@return string the rendering result
Recursively renders the menu items ( without the container tag ) . @param array $items the menu items to be rendered recursively @return string the rendering result
protected function renderItems($items)
    {
        $n = count($items);
        $lines = [];
        foreach ($items as $i => $item) {
            if (is_string($item)) {
                $lines[] = $item;
                continue;
            }
            $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
            $tag = ArrayHelper::remove($options, 'tag', 'li');
            $class = [];
            if ($item['active']) {
                $class[] = $this->activeCssClass;
            }
            if ($i === 0 && $this->firstItemCssClass !== null) {
                $class[] = $this->firstItemCssClass;
            }
            if ($i === $n - 1 && $this->lastItemCssClass !== null) {
                $class[] = $this->lastItemCssClass;
            }
            if (!empty($class)) {
                if (empty($options['class'])) {
                    $options['class'] = implode(' ', $class);
                } else {
                    $options['class'] .= ' ' . implode(' ', $class);
                }
            }
            $menu = $this->renderItem($item);
            if (!empty($item['items'])) {
                $menu .= strtr($this->submenuTemplate, [
                    '{show}' => $item['active'] ? "style='display: block'" : '',
                    '{items}' => $this->renderItems($item['items']),
                ]);
                if (isset($options['class'])) {
                    $options['class'] .= ' treeview';
                } else {
                    $options['class'] = 'treeview';
                }
            }
            $lines[] = Html::tag($tag, $menu, $options);
        }
        return implode("\n", $lines);
    }
protected function renderItems ( $ items ) { $ n = count ( $ items ) ; $ lines = [ ] ; foreach ( $ items as $ i => $ item ) { if ( is_string ( $ item ) ) { $ lines [ ] = $ item ; continue ; } $ options = array_merge ( $ this -> itemOptions , ArrayHelper :: getValue ( $ item , 'options' , [ ] ) ) ; $ tag = ArrayHelper :: remove ( $ options , 'tag' , 'li' ) ; $ class = [ ] ; if ( $ item [ 'active' ] ) { $ class [ ] = $ this -> activeCssClass ; } if ( $ i === 0 && $ this -> firstItemCssClass !== null ) { $ class [ ] = $ this -> firstItemCssClass ; } if ( $ i === $ n - 1 && $ this -> lastItemCssClass !== null ) { $ class [ ] = $ this -> lastItemCssClass ; } if ( ! empty ( $ class ) ) { if ( empty ( $ options [ 'class' ] ) ) { $ options [ 'class' ] = implode ( ' ' , $ class ) ; } else { $ options [ 'class' ] .= ' ' . implode ( ' ' , $ class ) ; } } $ menu = $ this -> renderItem ( $ item ) ; if ( ! empty ( $ item [ 'items' ] ) ) { $ menu .= strtr ( $ this -> submenuTemplate , [ '{show}' => $ item [ 'active' ] ? " style='display: block' " : '' , '{items}' => $ this -> renderItems ( $ item [ 'items' ] ) , ] ) ; if ( isset ( $ options [ 'class' ] ) ) { $ options [ 'class' ] .= ' treeview' ; } else { $ options [ 'class' ] = 'treeview' ; } } $ lines [ ] = Html :: tag ( $ tag , $ menu , $ options ) ; } return implode ( " \n " , $ lines ) ; }
Recursively renders the menu items (without the container tag).
Recursively renders the menu items ( without the container tag ) .