0

I have been working on a Symfony+SonataAdmin project, and we got stuck on Sonata KnpMenu ordering of elements.

First we used both Sonada Admin for insertion on the menu and EventListeners to add more menu items based on other routes we needed there. That worked fine. The problem is: when we used both native Admin and EventListeners to add options, their alphabetical order broke up, and options got separated on something like:

A option (EVTL)

E option (EVTL)

F option (EVTL)

B option (Adm)

C option (Adm)

D option (Adm)

Tried looking around a lot of places, and no one could help me with this.

Khadija
  • 310
  • 1
  • 9

1 Answers1

1

I tried to achieve something similiar and I solve it like the example below (i do not know if there is beter solution, but that worked for me). I just created event subcriber:

class ConfigureMenuEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            ConfigureMenuEvent::SIDEBAR => ['onConfigureMenu', 10]
        ];
    }

    public function onConfigureMenu(ConfigureMenuEvent $event)
    {
        $children = $event->getMenu()->getChildren();

        // todo some sorting operation with array

        $event->getMenu()->setChildren($children);
    }

}