em = $entityManager; $this->adminUrlGenerator = $adminUrlGenerator; } public static function getSubscribedEvents() { return [ AfterCrudActionEvent::class => ['overrideSortAction'], ]; } public function overrideSortAction(AfterCrudActionEvent $event) { $actions = $event->getResponseParameters()->get('global_actions'); if ($actions) { foreach ($actions as $i=>$action) { //récriture du bouton 'retour au parent' if ($action->getName() == 'index_parent') { $entity = $event->getAdminContext()->getEntity()->getInstance(); if ($entity !== null) { if($entity->getParent() !==null){ $url = $this->adminUrlGenerator ->setController($event->getAdminContext()->getCrud()->getControllerFqcn()) ->set('entityId', $entity->getParent()->getId()) ->generateUrl(); $action->setLinkUrl($url); } }else{ unset($actions[$i]); } } if ($action->getName() == 'sort') { $entityId = $event->getAdminContext()->getRequest()->get('entityId'); if ($entityId != null) { $url = $this->adminUrlGenerator ->setController($event->getAdminContext()->getCrud()->getControllerFqcn()) ->setAction($action->getName()) ->set('entityId', $entityId) ->generateUrl(); $action->setLinkUrl($url); } } } } } }