phpsymfonysonata-adminsonataknpmenubundle

Sonata Admin Custom Controller in Menu Override existing ones


I try to add a custom Controller/Page to the Knp Menu in Sonata Admin. I have bring it allready to work that the menu shows me the link in the navigation. I do it like this in the config:

    groups:
             User:
                  label:            User
                  items:
                      - route:        user_index
                        label:        User Profile
                      - route:        user_edit
                        label:        User Edit
                      - route:        user_password
                        label:        User Password
                  roles: [ ROLE_USER]

My Problem is my existing Sonata Admin Controllers are not shown in the menu when i activate this setting. What can i do to add and not override? What i found is to maybe register a listener and extend there the menu. But i found it must be easier than that.

What is the best way to do this? THX


Solution

  • I had the same problem and I solved it by adding an empty menu item with the same label as the default Sonata items (in my situation that group was called admin):

    sonata_admin:
        templates:
            # default global templates
            layout: SonataAdminBundle::layout.html.twig
        dashboard:
            groups:
                admin: ~
                User:
                    label:            User
                    items:
                        - route:        user_index
                          label:        User Profile
                        - route:        user_edit
                          label:        User Edit
                        - route:        user_password
                          label:        User Password
                    roles: [ ROLE_USER]