您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.9KB

  1. <?php
  2. namespace Lc\SovBundle\EventSubscriber\Action;
  3. use Doctrine\ORM\PersistentCollection;
  4. use Doctrine\ORM\Query;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
  7. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  8. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  9. use Gedmo\Translatable\TranslatableListener;
  10. use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
  11. use Lc\SovBundle\Doctrine\EntityManager;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use function Symfony\Component\Translation\t;
  14. class ActionEasyAdminSubscriber implements EventSubscriberInterface
  15. {
  16. protected $em;
  17. protected $adminUrlGenerator;
  18. public function __construct(EntityManager $entityManager, AdminUrlGenerator $adminUrlGenerator)
  19. {
  20. $this->em = $entityManager;
  21. $this->adminUrlGenerator = $adminUrlGenerator;
  22. }
  23. public static function getSubscribedEvents()
  24. {
  25. return [
  26. AfterCrudActionEvent::class => ['overrideSortAction'],
  27. ];
  28. }
  29. public function overrideSortAction(AfterCrudActionEvent $event)
  30. {
  31. $actions = $event->getResponseParameters()->get('global_actions');
  32. if ($actions) {
  33. foreach ($actions as $action) {
  34. if ($action->getName() == 'sort') {
  35. $entityId = $event->getAdminContext()->getRequest()->get('entityId');
  36. if ($entityId != null) {
  37. $url = $this->adminUrlGenerator
  38. ->setController($event->getAdminContext()->getCrud()->getControllerFqcn())
  39. ->setAction($action->getName())
  40. ->set('entityId', $entityId)
  41. ->generateUrl();
  42. $action->setLinkUrl($url);
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }