Cannot add more than two item in Submenu
darkiron opened this issue · comments
Vincent commented
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 ?
Christophe Coevoet commented
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.
Vincent commented
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.
Christophe Coevoet commented
I'm closing this, as a reproducing case (independent from Sylius) was not provided