KnpLabs / KnpMenu

Menu Library for PHP

Home Page:https://knplabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add more than two item in Submenu

darkiron opened this issue · comments

Hi, I try to add one more item in my submenu in Sylius admin by Service.

http://docs.sylius.org/en/latest/customization/menu.html#url

$newSubmenu
            ->addChild('new-subitem',['route' => 'XX'])
            ->setLabel('XX')
            ->setName('toto');

        $newSubmenu
            ->addChild('hhh',['route' => 'XX2'])
            ->setLabel('XX 2')
            ->setName('tata');

But I have only one. You can help-me ?

Can you provide a reproducing case ? I'm using KnpMenu since years, and I definitely have multiple children by menu item.
and if this cannot be reproduced outside Sylius, it would be best to report this to Sylius.

I finde a solution :

public function addAdminMenuItems(MenuBuilderEvent $event){
        $menu = $event->getMenu();
        $factory = $event->getFactory();

        $newSubmenu = $menu
            ->addChild('new')
            ->setLabel('xx')
            ->setName('xx.xx')
        ;

        $items[] = 
            $factory->createItem('xx.xx',['route' => 'xx'] )
                    ->setLabel('xx xx xx')
        ;
        $items[] = 
            $factory->createItem('xx.xx',['route' => 'xx'])
                    ->setLabel('xx xx')
        ;
    
       $newSubmenu->setChildren($items);
    }

Before child is not erase by the last.

I'm closing this, as a reproducing case (independent from Sylius) was not provided