0

In my one module i have t display only global data and admin can edit it .

I want to create module for that , but it is going to list page but i need direct edit page where admin can edit global values in sonata admin.

Any idea ?

Thanks in advance

Parth Khatri
  • 277
  • 1
  • 10
  • In Sonata Admin everything sticks to an Entity with that you can choose which actions should be allowed ... for example list, edit, show and so on ... what you mean with "direct edit page"? I assume you need some view to choose the record you want to edit ... – Jim Panse Nov 08 '17 at 08:22
  • Thanks jim , I dont want listing page whenever i click on left menu i want that direct create page opens not list page. – Parth Khatri Nov 08 '17 at 08:56

1 Answers1

0

Ok, here is what you can do ...

Create a MenuBuilderListener class to let them listen to the menu building event by registering to the sidebar event

In your services.yml

    app.menu_listener:
        class: AppBundle\Listener\MenuBuilderListener
        tags:
            - { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: addMenuItems }

In your class, search for the menu-item you want to change to "only edit" ...

class MenuBuilderListener
{
    public function addMenuItems(ConfigureMenuEvent $event)
    {
        $event->getMenu()->removeChild('the_name_of_your_menu_item');
        $event->getMenu()->addChild('the_name_of_your_menu_item', ['route' => 'your_route_to_create_view']);
    }

}

Mabe in newer KnpMenu Version there should be a setRoute Method directly for the MenuItem object, in my version it doesn't.

Doing this, your item should be replaced with the one pointing to your create route. To get avalable routes use the debugger in console with debug:router

Don't forget to block other routes if you dont want to list/edit and so on ...

Jim Panse
  • 2,220
  • 12
  • 34