设置子菜单

@param array $buttons

@return MenuItem
2953
public function buttons($buttons)
    {
        if ($buttons instanceof Closure) {
            $buttons = $buttons($this);
        }

        if (!is_array($buttons)) {
            exit('子菜单必须是数组或者匿名函数返回数组');
        }

        $this->with('sub_button', $buttons);

        return $this;
    }
444927
protected function filter(array $categories)
    {
        // 过滤空的子分类
        foreach ($categories as $i => $category) {
            if (!isset($category['navs']) || !$category['navs']) {
                unset($categories[$i]);
                continue;
            }
            foreach ($category['navs'] as $j => $subCategories) {
                if (!isset($subCategories['navs']) || !$subCategories['navs']) {
                    unset($categories[$i]['navs'][$j]);
                }
            }
        }

        // 过滤空的父分类
        foreach ($categories as $i => $category) {
            if (!isset($category['navs']) || !$category['navs']) {
                unset($categories[$i]);
            }
        }

        return $categories;
    }
1011860
protected function reduceMenu (Menu $menu)
    {
        $reduced = ['button' => []];

        foreach ($menu->getItems() as $menuItem) {
            $reduced['button'][] = $this->reduceItem($menuItem);
        }

        return $reduced;
    }
332800
public function setButtons(array $buttons)
    {
        collect($buttons)->map(function ($button) {
            $this->setButton($button);
        });

        return $this;
    }
500168
private function displayHTML($menus)
    {
        $build    = [];
        $manager  = $this->getTreeManager();

        /** @var \MakinaCorpus\Umenu\Menu $menu */
        foreach ($menus as $menu) {
            if ($menu->isSiteMain() || !$menu->hasRole()) {
                $tree = $manager->buildTree($menu->getId(), true);
                if (!$tree->isEmpty()) {
                    $build[$menu->getTitle()] = $tree;
                }
            }
        }

        return theme('ucms_seo_sitemap', ['menus' => $build]);
    }
525774
public function toButtons()
    {
        $data = [];

        $index = 0;
        /** @var $menu WeChatMenu */
        foreach ($this->data as $menu) {
            if ($this->firstLevelMaxItems >= $index) {
                $data[] = $menu->toButton();
                ++$index;
            } else {
                break;
            }
        }

        return ['button' => $data];
    }
404091
public function setObjectActions(array $actions)
    {
        $this->parsedObjectActions = false;

        $actions = $this->mergeActions($this->defaultObjectActions(), $actions);

        /** Enable seamless button group */
        if (isset($actions['edit'])) {
            $actions['edit']['actionType'] = 'seamless';
        }

        $this->objectActions = $actions;

        return $this;
    }
460955
public function defaultButtons(array $options = [])
    {
        $options['size'] = isset($options['size']) ? $options['size'] : 4;
        return '<div class="form-group">
                                <div class="col-sm-' . $options['size'] . ' col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">' . yii::t('cms', 'Save') . '</button>
                                    <button class="btn btn-white" type="reset">' . yii::t('cms', 'Reset') . '</button>
                                </div>
                            </div>';
    }
221594
public function setItems(array $items)
    {
        $this->content = new HtmlElements();

        foreach ($items as $item) {
            $this->addItem($item);
        }

        return $this;
    }
295217
public static function items($menu = 'sidebar', $items = null)
    {
        if (!is_string($menu)) {
            throw new \UnexpectedValueException('Menu id is not a string');
        }

        if (!empty($items)) {
            self::$_items[$menu] = $items;
        }

        if (!array_key_exists($menu, self::$_items)) {
            Log::error('Invalid menu: ' . $menu);
            return [];
        }

        return self::$_items[$menu];
    }
215611
public static function menu(array $items, $htmlOptions = array(), $depth = 0)
    {
        // todo: consider making this method protected.
        if (!empty($items)) {
            $htmlOptions['role'] = 'menu';
            $output = self::openTag('ul', $htmlOptions);
            foreach ($items as $itemOptions) {
                if (is_string($itemOptions)) {
                    if ($itemOptions == '---') {
                        $output .= self::menuDivider();
                    } else {
                        $output .= $itemOptions;
                    }
                } else {
                    if (TbArray::popValue('visible', $itemOptions, true)  === false) {
                        continue;
                    }
                    // todo: consider removing the support for htmlOptions.
                    $options = TbArray::popValue('htmlOptions', $itemOptions, array());
                    if (!empty($options)) {
                        $itemOptions = TbArray::merge($options, $itemOptions);
                    }
                    $label = TbArray::popValue('label', $itemOptions, '');
                    if (TbArray::popValue('active', $itemOptions, false)) {
                        self::addCssClass('active', $itemOptions);
                    }
                    if (TbArray::popValue('disabled', $itemOptions, false)) {
                        self::addCssClass('disabled', $itemOptions);
                    }
                    if (!isset($itemOptions['linkOptions'])) {
                        $itemOptions['linkOptions'] = array();
                    }
                    $icon = TbArray::popValue('icon', $itemOptions);
                    if (!empty($icon)) {
                        $label = self::icon($icon) . ' ' . $label;
                    }
                    $items = TbArray::popValue('items', $itemOptions, array());
                    $url = TbArray::popValue('url', $itemOptions, false);
                    if (empty($items)) {
                        if (!$url) {
                            $output .= self::menuHeader($label);
                        } else {
                            $itemOptions['linkOptions']['tabindex'] = -1;
                            $output .= self::menuLink($label, $url, $itemOptions);
                        }
                    } else {
                        $output .= self::menuDropdown($label, $url, $items, $itemOptions, $depth);
                    }
                }
            }
            $output .= '</ul>';
            return $output;
        } else {
            return '';
        }
    }
1134204
private function validateButtons($buttons)
    {
        if ($buttons === false)
            return $buttons;

        foreach($buttons as $q=>$w)
        {
            $buttons[$q] = ButtonReactManager::validateButton($w,$this->getTranslator(),$this->getTemplateManager());
        }
        return $buttons;
    }
45427
protected function createMenus($menus)
    {
        $locations = [];

        foreach ($menus as $menu) {
            $menu_id = $this->createMenu($menu['name']);

            if ($menu_id) {
                $locations[$menu['location']] = $menu_id;
                $this->populateMenu($menu_id, $menu['items']);
            }
        }

        set_theme_mod('nav_menu_locations', $locations);
    }
394470
public function setButtons(array $buttons): self
    {
        $this->isValidArray($buttons, 1);

        $this->buttons = $buttons;

        return $this;
    }
450900
public function getItems()
    {
        if (null === $this->items) {
            /** @var \Darvin\AdminBundle\Menu\Item[] $items */
            $items = $skipped = [];

            foreach ($this->itemFactories as $itemFactory) {
                foreach ($itemFactory->getItems() as $item) {
                    if (isset($items[$item->getName()])) {
                        throw new MenuException(sprintf('Menu item "%s" already exists.', $item->getName()));
                    }
                    if (null === $item->getIndexUrl() && null === $item->getNewUrl()) {
                        $skipped[$item->getName()] = true;

                        continue;
                    }

                    $associatedObject = $item->getAssociatedObject();

                    if (!empty($associatedObject)
                        && (!$this->authorizationChecker->isGranted(Permission::VIEW, $associatedObject) && !$this->authorizationChecker->isGranted(Permission::CREATE_DELETE, $associatedObject))
                    ) {
                        $skipped[$item->getName()] = true;

                        continue;
                    }

                    $items[$item->getName()] = $item;
                }
            }

            $this->sortItems($items);

            foreach ($items as $item) {
                if (!$item->hasParent()) {
                    continue;
                }

                $parentName = $item->getParentName();

                if (isset($skipped[$parentName])) {
                    continue;
                }
                if (!isset($items[$parentName])) {
                    $items[$parentName] = $this->createItemGroup($parentName, $item->getPosition());
                }

                $parent = $items[$parentName];
                $parent->addChild($item);
            }
            foreach ($items as $key => $item) {
                if ($item->hasParent() && !isset($skipped[$item->getParentName()])) {
                    unset($items[$key]);
                }
            }

            $this->sortItems($items);

            $this->items = $items;
        }

        return $this->items;
    }
1253318
public function override_children(array $children) {
        $this->children = array();
        foreach ($children as $child) {
            if ($child instanceof custom_menu_item) {
                $this->children[] = $child;
            }
        }
    }
639066
protected function parseMenu($menus)
    {
        $menuItems = array();
        foreach ($menus as $name => $config) {
            if (!array_key_exists('route', $config) && !array_key_exists('uri', $config)) {
                throw new RuntimeException('"route" key must be set.');
            }

            $route = array_key_exists('route', $config) ? $config['route'] : $config['uri'];

            $menuItems[$route] = array();
            if (array_key_exists('child', $config)) {
                $menuItems[$route]['child'] = $this->parseMenu($config['child']);
            }

            $menuItems[$route]['label'] = $name;
            $menuItems[$route]['role'] = array_key_exists('role', $config) ? $config['role'] : 'ROLE_USER';
            $menuItems[$route]['icon'] = array_key_exists('icon', $config) ? $config['icon'] : 'fa-bars';
            $menuItems[$route]['extra'] = array_key_exists('extra', $config) ? $config['extra'] : '';
        }

        return $menuItems;
    }