Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

50 lines
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. }