Use service to create main admin navigation.

@param array $menuGroups

@return \Knp\Menu\ItemInterface
963048
public function createAdminSideMenu()
    {
        $groups = $this->adminPool->getDashboardGroups();
        $adminMenu = $this->factory->createItem('admin_side_menu');

        if (!$this->authorizationChecker->isGranted('ROLE_SONATA_ADMIN')) {
            return $adminMenu;
        }

        $iconSize = 'large';
        $firstLevelClass = 'first-level';

        $largeMenu = $adminMenu->addChild(
            'large',
            [
                'attributes' => ['class' => 'nav-custom'], ]
        );
        $smallMenu = $adminMenu->addChild(
            'small',
            [
                'attributes' => ['class' => 'nav-custom nav-custom-small', 'style' => 'margin-top: 50px;'], ]
        );

        $largeMenu->addChild(
            $this->translator->trans('admin.menu.dashboard', [], 'PageAdmin'),
            [
                'uri' => $this->router->generate('sonata_admin_dashboard'),
                'current' => $this->request->get('_sonata_admin') ? false : true,
                'attributes' => ['class' => $firstLevelClass, 'icon' => 'glyphicon glyphicon-dashboard', 'icon_size' => 'glyphicon-'.$iconSize],
                'linkAttributes' => ['class' => 'pull-left first-level-text'],
            ]
        );

        $menu = $largeMenu;
        foreach ($this->menuGroups as $key => $item) {
            foreach ($item['items'] as $mainMenu) {
                if (array_key_exists($mainMenu, $groups)) {
                    $group = $groups[$mainMenu];
                    if (count($group['items']) > 0) {
                        $first = reset($group['items']);
                        if ($first instanceof AdminInterface && $first->hasRoute('list')) {
                            $current = false;
                            $icon = 'glyphicon-unchecked';
                            $iconType = 'glyphicon';

                            if ($this->request->get('_sonata_admin') == $first->getCode()) {
                                $current = true;
                            }

                            if (method_exists($first, 'getIcon')) {
                                $icon = $first->getIcon();
                            }

                            if ($first->getExtensions()) {
                                foreach ($first->getExtensions() as $extension) {
                                    if (method_exists($extension, 'getIcon')) {
                                        $icon = $extension->getIcon();
                                        break;
                                    }
                                }
                            }

                            if (substr($icon, 0, '2') == 'fa') {
                                $iconType = 'fa';
                            }

                            $mainItem = $menu->addChild(
                                $this->translator->trans($group['label'], [], $group['label_catalogue'] != 'SonataAdminBundle' ? $group['label_catalogue'] : $first->getTranslationDomain()),
                                [
                                    'uri' => $first->generateUrl('list'),
                                    'current' => $current,
                                    'attributes' => ['class' => $firstLevelClass, 'icon' => sprintf('%s %s', $iconType, $icon), 'icon_size' => sprintf('%s-%s', $iconType, $iconSize)],
                                    'linkAttributes' => ['class' => 'pull-left first-level-text'],
                                ]
                            );

                            if (count($group['items']) > 1) {
                                foreach ($group['items'] as $subItem) {
                                    $current = false;
                                    if ($this->request->get('_sonata_admin') == $subItem->getCode()) {
                                        $current = true;
                                    }
                                    if ($subItem instanceof AdminInterface && $subItem->hasRoute('list')) {
                                        $mainItem->addChild(
                                            $this->translator->trans($subItem->getLabel(), [], $subItem->getTranslationDomain()),
                                            [
                                                'uri' => $subItem->generateUrl('list'),
                                                'current' => $current,
                                                'attributes' => ['class' => 'second-level', 'icon' => $icon, 'icon_size' => $iconSize],
                                            ]
                                        );
                                    }
                                }
                            }
                        }
                    }
                }
            }

            $iconSize = 'small';
            $firstLevelClass = 'first-level-small';
            $this->showOnlyCurrentChildren($menu);
            $menu = $smallMenu;
        }

        return $adminMenu;
    }
776024
public function createUserMenu()
    {
        $menu = $this->factory->createItem('root');

        if ($this->accountEnabled) {
            if (null !== $token = $this->tokenStorage->getToken()) {
                if ($this->authorization->isGranted('IS_AUTHENTICATED_FULLY') || $this->authorization->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
                    /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
                    $user = $token->getUser();
                    $item = $menu->addChild($user->getEmail(), ['uri' => '#']);
                    $item->addChild('ekyna_user.account.menu.my_profile', ['route' => 'fos_user_profile_show']);
                    if ($this->authorization->isGranted('ROLE_ADMIN')) {
                        $item->addChild('ekyna_user.account.menu.backend', ['route' => 'ekyna_admin']);
                    }
                    $item->addChild('ekyna_user.account.menu.logout', ['route' => 'fos_user_security_logout']);
                    return $menu;
                }
            }
            $menu->addChild('ekyna_user.account.menu.login', ['route' => 'fos_user_security_login']);
        }

        return $menu;
    }
1088013
public function addCurrentChildren()
    {
        foreach ($this->menu->getCurrentChildren() as $menuItem) {
            $this->addMenuItem($menuItem);
        }
        return $this;
    }
89904
public static function getMenu()
    {
        return (new \Mmi\Navigation\NavigationConfigElement)
            ->setId('admin-menu')
            ->setLabel('menu.index.index')
            ->setModule('cmsAdmin')
            ->addChild((new \Mmi\Navigation\NavigationConfigElement)
                ->setModule('cmsAdmin')
                ->setDisabled()
                ->setAction('password')
                ->setLabel('menu.index.password'))
            ->addChild((new \Mmi\Navigation\NavigationConfigElement)
                ->setModule('cmsAdmin')
                ->setAction('login')
                ->setIcon('fa-unlock-alt')
                ->setLabel('menu.index.login')
                ->setDisabled())
            ->addChild(
                (new \Mmi\Navigation\NavigationConfigElement)
                    ->setLabel('menu.container')
                    ->setIcon('fa-cog')
                    ->setUri('#')
                    ->addChild(NavPart\NavPartCategory::getMenu())
                    ->addChild(NavPart\NavPartText::getMenu())
                    ->addChild(NavPart\NavPartMail::getMenu())
                    ->addChild(NavPart\NavPartStat::getMenu())
                    ->addChild(NavPart\NavPartContact::getMenu())
                    ->addChild(NavPart\NavPartAuth::getMenu())
                    ->addChild(NavPart\NavPartSystem::getMenu())
            );
    }
731131
public function menuAction()
    {
        $params     = $this->params();
        $navigation = $this->getServiceLocator()
                           ->get( 'Grid\Menu\Model\Menu\Model' )
                           ->findNavigation( $params->fromRoute( 'id' ) );

        $view = new ViewModel( array(
            'navigation' => $navigation,
        ) );

        $this->getResponse()
             ->getHeaders()
             ->addHeaderLine( 'Content-Type', 'application/xml' );

        return $view->setTerminal( true );
    }
1262099
public function createSubnavMenu($menuName, $classes = 'nav nav-tabs nav-stacked')
    {
        $menu = $this->factory->createItem('root');

        if ($classes) {
            $menu->setChildrenAttribute('class', $classes);
        }

        /** @var $mainMenu Menu */
        $menuIterator = $this->getSubMenu($menuName, 1);

        if (!$menuIterator) {
            return $menu;
        }

        $startDepth = 2;

        $menu = $this->createMenu($menu, $menuIterator, $startDepth);
        $this->showOnlyCurrentChildren($menu);
        $this->setRecursiveAttribute($menu, ['class' => 'nav nav-list']);

        return $menu;
    }
155644
public function parents(array $parents): self
    {
        if ($parents === []) {
            return $this;
        }

        $data = [];

        foreach ($parents as $parent) {
            if (!isset($this->preparedGroups[$parent])) {
                throw new \LogicException(sprintf(
                    'Unable to find parent group: %s for route group: %s',
                    $parent,
                    $this->group
                ));
            }

            $data[] = $this->preparedGroups[$parent];
        }

        $old = $this->options->dump();
        $data = Arr::mergeRecursive(...$data);

        $this->options->bind($data);
        $this->options->bind($old);

        return $this;
    }
408035
public function render($group = null)
    {
        $this->config('content.url', Router::url($this->config('content.url')));
        $content = $this->formatTemplate('content', $this->config('content'));

        if ($group) {
            $this->config(array_shift($this->_config['childConfig']));
            $menu = new MenuGroup([$this->config()], $this->_here);
            $content .= $menu->render($group);
            $this->_active = $this->_active || $menu->active();
        }

        return $content;
    }
483136
protected function searchCorrectMenuEntryInArray($menuEntries)
    {
        foreach ($menuEntries as $key => $menuEntry) {
            if (trim($menuEntry->getTarget(), '/') === trim($this->framework->getRequest()->getRoute(), '/')) {
                return $menuEntry;
            }
            
            if ($menuEntry->hasChildren()) {
                $menuEntry = $this->searchCorrectMenuEntryInArray($menuEntry->getChildren());
                
                if ($menuEntry !== false) {
                    return $menuEntry;
                }
            }
        }
        
        return false;
    }
1314347
public function createSidebarMenu()
    {
        $menu = $this->factory->createItem('root');

        foreach ($this->pool->getAdminGroups() as $name => $group) {
            $extras = [
                'icon' => $group['icon'],
                'label_catalogue' => $group['label_catalogue'],
                'roles' => $group['roles'],
                'sonata_admin' => true,
            ];

            $menuProvider = $group['provider'] ?? 'sonata_group_menu';
            $subMenu = $this->provider->get(
                $menuProvider,
                [
                    'name' => $name,
                    'group' => $group,
                ]
            );

            $subMenu = $menu->addChild($subMenu);
            $subMenu->setExtras(array_merge($subMenu->getExtras(), $extras));
        }

        $event = new ConfigureMenuEvent($this->factory, $menu);
        $this->eventDispatcher->dispatch(ConfigureMenuEvent::SIDEBAR, $event);

        return $event->getMenu();
    }
1254069
public function buttonToolbar(array $buttonGroups, array $options = array()) {
        $options += [
            'templateVars' => []
        ];
        return $this->formatTemplate('buttonToolbar', [
            'content' => implode('', $buttonGroups),
            'attrs' => $this->templater()->formatAttributes($options, ['vertical']),
            'templateVars' => $options['templateVars']
        ]);
    }
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;
    }
842173
public function getMenu(string $menuClass, $options = []): ItemInterface
    {
        // Merge Options
        $options = array_merge($this->defaultOptions, $options);

        // Get Menu
        $menu = $this->container->has($menuClass) ? $this->container->get($menuClass) : new $menuClass();

        // Render
        if ($menu instanceof MenuInterface) {
            return $this->itemProcess->processMenu($menu->createMenu($options), $options);
        }

        return false;
    }
1303967
protected static function menuitem_for_controller($controllerClass)
    {
        $urlBase = AdminRootController::admin_url();
        $urlSegment   = Config::inst()->get($controllerClass, 'url_segment');
        $menuPriority = Config::inst()->get($controllerClass, 'menu_priority');
        $ignoreFromMenu = Config::inst()->get($controllerClass, 'ignore_menuitem');

        // Don't add menu items defined the old way, or for controllers that are set to be ignored
        if (!$urlSegment || $ignoreFromMenu) {
            return null;
        }

        $link = Controller::join_links($urlBase, $urlSegment) . '/';

        // doesn't work if called outside of a controller context (e.g. in _config.php)
        // as the locale won't be detected properly. Use {@link LeftAndMain->MainMenu()} to update
        // titles for existing menu entries
        $menuTitle = LeftAndMain::menu_title($controllerClass);

        return new CMSMenuItem($menuTitle, $link, $controllerClass, $menuPriority);
    }
573071
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var AuthorizationService $authorizationService */
        $authorizationService = $serviceLocator->get('ZfcRbac\Service\AuthorizationService');

        /** @var RoleService $roleService */
        $roleService = $serviceLocator->get('ZfcRbac\Service\RoleService');

        return new NavigationRbacListener($authorizationService, $roleService);
    }
274979
public function getChildren(MenuItem $parent = null)
    {
        if ($parent === null) {
            return $this->getTopChildren();
        }
        /* @var $request Request */
        $request = $this->container->get('request_stack')->getCurrentRequest();
        $result = array();
        foreach ($this->getAdaptors() as $menuAdaptor) {
            $menuAdaptor->adaptChildren($this, $result, $parent, $request);
        }

        return $result;
    }
558095
public function create($menu = null)
    {
        $model = $this->repository->getModel();

        return view('menulinks::admin.create')
            ->with(compact('model', 'menu'));
    }