I use the example provided by Sonata in my explanation, the main Post / Comment relation.
You should have a parent / child (oneTomany / manyToOne) link between your Post (parent) and Comment (child) objects.
You must add addChild arguments to the service declaration that target the child admin service:
services.yml
sonata.news.admin.comment: class: Sonata\NewsBundle\Admin\CommentAdmin arguments: [~, Sonata\NewsBundle\Model\Comment, SonataNewsBundle:CommentAdmin] tags: - {name: sonata.admin, manager_type: orm, group: "Content"} sonata.news.admin.post: class: Sonata\NewsBundle\Admin\PostAdmin arguments: [~, Sonata\NewsBundle\Model\Post, SonataNewsBundle:PostAdmin] tags: - {name: sonata.admin, manager_type: orm, group: "Content"} calls: - [addChild, ['@sonata.news.admin.comment']]
In your CommentAdmin class, you need to add the AssociationMapping property to filter this child by the parent.
CommentAdmin
class CommentAdmin extends Admin { protected $parentAssociationMapping = 'post'; ... }
Then you will have a new route available: / parent / ID / child / list, you can use the console to determine the identifier of your new route (php app / console router: debug). If you need an easy way to access this in the administrator, I suggest adding a button to the direct list of administrators to access her child comments:
Create a template that adds a button to access comments for children:
post_comments.html.twig
<a class="btn btn-sm btn-default" href="{{ path('OUR_NEW_CHILD_ROUTE_ID', {'id': object.id }) }}">Comments</a>
Then add the button action in the parent Admin in this case, PostAdmin:
Postadmin
class PostAdmin extends Admin { protected function configureListFields(ListMapper $listMapper) { $listMapper->add('_action', 'actions', array( 'actions' => array( 'show' => array(), 'edit' => array(), 'comments' => array('template' => 'PATH_TWIG') ) )) } }
Hope you learned a little more about how to set up parent / child admins.