Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

FlashMessageAdminEventSubscriber.php 1.8KB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 FlashMessageAdminEventSubscriber 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. }