|
- <?php
-
- namespace Lc\SovBundle\EventSubscriber\Action;
-
- use Doctrine\ORM\PersistentCollection;
- use Doctrine\ORM\Query;
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Gedmo\Translatable\TranslatableListener;
- use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
- use function Symfony\Component\Translation\t;
-
- class ActionEasyAdminSubscriber implements EventSubscriberInterface
- {
- protected $em;
- protected $adminUrlGenerator;
-
- public function __construct(EntityManager $entityManager, AdminUrlGenerator $adminUrlGenerator)
- {
- $this->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);
- }
- }
- }
- }
- }
-
-
- }
|