Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

50 linhas
1.8KB

  1. <?php
  2. namespace Lc\SovBundle\EventSubscriber;
  3. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\Translation\TranslatableMessage;
  9. class EasyAdminEventSubscriber implements EventSubscriberInterface
  10. {
  11. protected $session ;
  12. public function __construct(SessionInterface $session)
  13. {
  14. $this->session = $session ;
  15. }
  16. public static function getSubscribedEvents(): array
  17. {
  18. return [
  19. AfterEntityPersistedEvent::class => ['flashMessageAfterPersist'],
  20. AfterEntityUpdatedEvent::class => ['flashMessageAfterUpdate'],
  21. AfterEntityDeletedEvent::class => ['flashMessageAfterDelete'],
  22. ];
  23. }
  24. public function flashMessageAfterPersist(AfterEntityPersistedEvent $event): void
  25. {
  26. $this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.create', [
  27. '%name%' => (string) $event->getEntityInstance(),
  28. ]));
  29. }
  30. public function flashMessageAfterUpdate(AfterEntityUpdatedEvent $event): void
  31. {
  32. $this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.update', [
  33. '%name%' => (string) $event->getEntityInstance(),
  34. ]));
  35. }
  36. public function flashMessageAfterDelete(AfterEntityDeletedEvent $event): void
  37. {
  38. $this->session->getFlashBag()->add('success', new TranslatableMessage('flash_message.delete', [
  39. '%name%' => (string) $event->getEntityInstance(),
  40. ]));
  41. }
  42. }