@param \Darvin\AdminBundle\Menu\ItemFactoryInterface $itemFactory Menu item factory

@throws \Darvin\AdminBundle\Menu\MenuException
356986
public function addItemFactory(ItemFactoryInterface $itemFactory)
    {
        $class = get_class($itemFactory);

        if (isset($this->itemFactories[$class])) {
            throw new MenuException(sprintf('Item factory "%s" already added to menu.', $class));
        }

        $this->itemFactories[$class] = $itemFactory;
    }
902402
public function withItem (MenuItem $item)
    {
        if (count($this->items) >= 3) {
            throw new LengthException("Maximum of 3 items allowed in a menu.");
        }

        $cloned = clone $this;
        $cloned->items[] = $item;

        return $cloned;
    }
1325620
public function addMenuItem(MenuEvent $e)
    {
        $array = $e->getMenuConfig();

        $this->menu->addChild(
            $this->factory->createItem($array['name'], $array)
        );
    }
719113
public function add($name, ItemInterface $item)
    {
        if (isset($this->relationships[$name]) === false) {
            $this->relationships[$name] = [];
        }

        unset($this->relationships[$name][$item->getId()]);

        $this->relationships[$name][$item->getId()] = $item;
    }
416523
public function main(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('admin_main');

        $menu->setChildrenAttribute('class', isset($options['class']) ? $options['class'] : 'sidebar-menu'); // nav navbar-nav
        $menu->setChildrenAttribute('data-widget', 'tree');
        $menu->addChild('Dashboard',     ['route' => 'cms_admin_index'])->setExtras(['beforeCode' => '<i class="fa fa-dashboard"></i>']);

        foreach ($this->container->get('cms.module')->all() as $module) {
            $module->buildAdminMenu($menu);
        }

        $systemItems = $menu->addChild('System', ['route' => 'cms_admin_system'])
            ->setAttribute('class', 'treeview')
            ->setExtras([
                'afterCode'  => '<i class="fa fa-angle-left pull-right"></i>',
                'beforeCode' => '<i class="fa fa-gear"></i>',
            ])
        ;
        $systemItems->setChildrenAttribute('class', 'treeview-menu');

        $systemItems->addChild('Site structure', ['route' => 'cms_admin_structure'])->setExtras(['beforeCode' => '<i class="fa fa-folder-open"></i>']);
        $systemItems->addChild('Files',          ['route' => 'cms_admin_files'])->setExtras(['beforeCode' => '<i class="fa fa-download"></i>']);
        $systemItems->addChild('Users',          ['route' => 'cms_admin_user'])->setExtras(['beforeCode' => '<i class="fa fa-users"></i>']);
        $systemItems->addChild('Configuration',  ['route' => 'smart_core_settings'])->setExtras(['beforeCode' => '<i class="fa fa-gears"></i>']);
        $systemItems->addChild('Appearance',     ['route' => 'cms_admin_appearance'])->setExtras(['beforeCode' => '<i class="fa fa-image"></i>']);
        $systemItems->addChild('Backup',         ['route' => 'cms_admin_backup'])->setExtras(['beforeCode' => '<i class="fa fa-file-archive-o "></i>']);

        $menu->addChild('Reports',       ['route' => 'cms_admin_reports'])->setExtras(['beforeCode' => '<i class="fa fa-bar-chart"></i>']);
        //$menu->addChild('Help',          ['route' => 'cms_admin_help'])->setExtras(['beforeCode' => '<i class="fa fa-question"></i>']);

        return $menu;
    }
842079
protected function addLinkURI(ItemInterface $menu, $label, $uri)
    {
        $item = $menu->addChild($label, array('uri' => $uri));
        $item->setExtra('translation_domain', $this->translation_domain);

        if ($this->isCurrentUri($item->getUri())) {
            $item->setAttribute('class', 'active');
        }

        return $item;
    }
1124898
public function processMenu(ItemInterface $menu, array $options = []): ItemInterface
    {
        // Dispatch Event
        if ($menu->isEvent()) {
            $this->eventDispatcher->dispatch($menu->getId() . '.event', new PdMenuEvent($menu));
        }

        // Set Current URI
        $this->currentUri = $this->router->getContext()->getPathInfo();

        // Process Menu
        $this->recursiveProcess($menu, $options);

        return $menu;
    }
730888
public function render(ItemInterface $item, array $options = []): string
    {
        return $this->engine->render($options['template'], ['menu' => $item, 'options' => $options]);
    }
1036148
public function addMenuItem(Request $request, array $item, MenuItem $menu)
    {
        $attributes = array();

        // if the menu item has a name, add it as a css class.
        if ($name = $item['name']) {
            $attributes['class'] = $name;
        }
        if (empty($item['path'])) {
            $uri = null;
        } elseif (preg_match('!^(?:https?://|mailto:)!', $item['path'])) {
            $uri = $item['path'];
        } else {
            $baseUrl = $request->getBaseUrl();
            $uri = $baseUrl . '/' . ltrim($item['path'], '/');
        }

        $menuItem = $menu->addChild(
            $item['id'],
            array(
                'uri' => $uri,
                'attributes' => $attributes,
                'label' => $item['title']
            )
        );

        if (!empty($item['json_data'])) {
            $item['json_data'] = @json_decode($item['json_data']);
        }

        $menuItem->setExtras($item);
        return $menuItem;
    }
787214
protected function _addMenu(ItemInterface $menu, array $options)
    {
        $this->_menus[$menu->getName()] = $menu;
        $this->_menuConfigurations->attach($menu, $options);
    }
827261
public function showOnlyCurrentChildren(ItemInterface $menu)
    {
        $itemIterator = new RecursiveItemIterator($menu->getIterator());

        $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterator as $menuItem) {
            /** @var \Knp\Menu\MenuItem $menuItem */
            if (!$this->matcher->isCurrent($menuItem) && !$this->matcher->isAncestor($menuItem)) {
                $menuItem->setDisplayChildren(false);
            }
        }
    }
1213601
public function addItem(MenuItem $item) {
        if($item instanceof ResourceMenuItem){
            throw new \InvalidArgumentException('ResourceMenuItem passed to Resource::addItem(MenuItem). You cannot nest ResourceMenuItems.');
        }

        $this->items[] = $item;

        return $this;
    }
651640
public function structure(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('admin_structure');

        $menu->setChildrenAttribute('class', isset($options['class']) ? $options['class'] : 'nav nav-pills');
        $menu->addChild('Create folder',  ['route' => 'cms_admin_structure_folder_create']);
        $menu->addChild('Connect module', ['route' => 'cms_admin_structure_node_create']);
        $menu->addChild('Regions',        ['route' => 'cms_admin_structure_region']);
        $menu->addChild('Trash',          ['route' => 'cms_admin_structure_trash']);

        return $menu;
    }
671408
public function buildMenu(ItemInterface $node, ItemEntity $item)
    {
        if ($item->getPath() && $this->fs->exists($item->getPath())) {
            $node->addChild('Fill folder', [
                'route' => 'item_folder_filler_fill',
                'routeParameters' => [
                    'id' => $item->getId(),
                    'name' => $item->getUrlName()
                ]
            ])
                ->setLinkAttribute('class', 'icon-label icon-fill');
        }
    }
1189745
protected function _renderItem(ItemInterface $item, array $options)
    {
        if (!$item->isDisplayed()) {
            return '';
        }

        $level = $item->getLevel();

        $class = (array)$item->getAttribute('class');

        if ($this->_matcher->isCurrent($item)) {
            $class[] = $options['currentClass'];
        } elseif (isset($options['ancestorClass']) &&
            $this->_matcher->isAncestor($item, $options['matchingDepth'])
        ) {
            $class[] = $options['ancestorClass'];
        }

        if (isset($options['firstClass']) &&
            $item->actsLikeFirst()
        ) {
            $class[] = $options['firstClass'];
        }
        if (isset($options['lastClass']) &&
            $item->actsLikeLast()
        ) {
            $class[] = $options['lastClass'];
        }

        $hasChildren = $item->hasChildren();
        if ($hasChildren &&
            $options['depth'] !== 0
        ) {
            if ($options['branchClass'] !== null &&
                $item->getDisplayChildren()
            ) {
                $class[] = $options['branchClass'];
            }
        } elseif ($options['leafClass'] !== null) {
            $class[] = $options['leafClass'];
        }

        $attributes = $item->getAttributes();
        if (!empty($class)) {
            $attributes['class'] = implode(' ', $class);
        }

        $templater = $this->templater();

        $attributes = $this->_formatAttributes($attributes, $item);

        $templates = (array)$item->getExtra('templates');
        $defaultTemplates = (array)$item->getExtra('defaultTemplates');
        $newTemplates = $templates + $defaultTemplates;
        if ($newTemplates) {
            $templater->push();
            $templater->add($newTemplates);
        }

        $templateVars = (array)$item->getExtra('templateVars');
        $defaultTemplateVars = (array)$item->getExtra('defaultTemplateVars');
        $currentDefaultTemplateVars = (array)$options['defaultTemplateVars'];
        $templateVars =
            $templateVars +
            $defaultTemplateVars +
            $currentDefaultTemplateVars;
        if (empty($templateVars)) {
            $templateVars = null;
        }
        $options['templateVars'] = $templateVars;

        $link = $this->_renderLink($item, $options);

        if ($hasChildren) {
            $nestedClass = (array)$item->getChildrenAttribute('class');
            if ($options['menuLevelClass'] !== null) {
                $nestedClass[] = $options['menuLevelClass'] . $level;
            }
            if ($options['nestedMenuClass'] !== null) {
                $nestedClass[] = $options['nestedMenuClass'];
            }
            $nestedAttributes = $item->getChildrenAttributes();
            $nestedAttributes['class'] = implode(' ', $nestedClass);
            $options['attributes'] = $nestedAttributes;

            $options['childrenTemplates'] = null;
            if ($newTemplates) {
                // item defines new templates that must be ignored by the children
                $options['childrenTemplates'] = $options['defaultTemplates'];
            }
            if ($defaultTemplates) {
                // item defines default templates that must be used by the children
                $options['childrenTemplates'] = $defaultTemplates;
            }

            if ($defaultTemplateVars) {
                // item defines default template vars that must be used by the children
                $options['defaultTemplateVars'] =
                    $defaultTemplateVars +
                    $currentDefaultTemplateVars;
            }

            $nested = $this->_renderNested($item, $options);
        } else {
            $nested = '';
        }

        $rendered = (string)$templater->format('item', [
            'attrs' => $attributes,
            'templateVars' => $templateVars,
            'link' => $link,
            'nest' => $nested
        ]);

        if ($newTemplates) {
            $templater->pop();
        }

        return $rendered;
    }
1345461
public function removeItem(ItemInterface $item)
    {
        $this->itemsChanged = true;
        $this->entity->removeItem($item);

        return $this;
    }
1054337
public void addMenuItem(CmsContextMenuItemWidget menuItem) {

        menuItem.setOverlay(this);

        m_menuItems.add(menuItem);
        m_root.add(menuItem);
    }