Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Child Admin route is not being generated - Sonata Admin Bundle

I'm trying to set up an Admin as a child of an other Admin in Sonata Admin Bundle.

I have 2 Admin classes:

  • CategoryAdmin
    This class contains the following method

    protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
    {            
         $id = $this->getRequest()->get('id');
    
         $menu->addChild(
             $this->trans('Projects'),
             array('uri' => $this->getChild('sonata.admin.project')->generateUrl('list', array('id' => $id)))
         );
    }
    
  • ProjectAdmin
    This class contains protected $parentAssociationMapping = 'category';
    category is the property in the model class representing the ManyToOne association.

I added the following lines to my service configuration for CategoryAdmin

calls:
    - [ addChild, ["@sonata.admin.project"]]

The routes for the child Admin are not being generated with this configuration. The link in the SideMenu (top menu) points to /admin/project/list?childId=1&id=1

Here is the output of the children of CategoryAdmin with dump()

array:1 [▼
    "sonata.admin.project" => ProjectAdmin {#406 ▶}
]

This means that the configuration for my child admin seems to be correct. I have no idea, why the routes for the child admin are not being generated.

I hope somebody can give me a hint, what the problem could be.

like image 526
temparus Avatar asked Oct 31 '22 09:10

temparus


2 Answers

Note for next gen sonata coders: If your route is not being generated, first check you didn't do:

protected function configureRoutes(RouteCollection $collection)
{
    //clear all routes except given !!!
    $collection->clearExcept(array('list', 'show'));
}

It costs me two days...

like image 88
d3uter Avatar answered Nov 08 '22 23:11

d3uter


Do you have the $baseRouteName and $baseRoutePattern overriden in your admin class ?

If you do, Sonata will generate both child and parent routes with the same name resulting in the parent routes overriding the child ones.

like image 26
jvasseur Avatar answered Nov 08 '22 23:11

jvasseur