From c47ed5240bfa23d52918d2ffee1190de5ff639aa Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 7 Jul 2024 09:02:48 +0200 Subject: [PATCH] Register ProfileChangeListener --- src/EventListener/ProfileChangeListener.php | 13 ++++++++++--- src/Resources/config/listeners.php | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/EventListener/ProfileChangeListener.php b/src/EventListener/ProfileChangeListener.php index 0c534c75..e38fdd4b 100644 --- a/src/EventListener/ProfileChangeListener.php +++ b/src/EventListener/ProfileChangeListener.php @@ -20,6 +20,13 @@ final class ProfileChangeListener implements EventSubscriberInterface { + private readonly EventDispatcherInterface $eventDispatcher; + + public function __construct(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } + /** * @return array */ @@ -30,9 +37,9 @@ public static function getSubscribedEvents(): array ]; } - public function profileChanged(FilterUserResponseEvent $event, string $eventName, EventDispatcherInterface $eventDispatcher): void + public function profileChanged(FilterUserResponseEvent $event): void { - $eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), NucleosUserEvents::USER_LOCALE_CHANGED); - $eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), NucleosUserEvents::USER_TIMEZONE_CHANGED); + $this->eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), NucleosUserEvents::USER_LOCALE_CHANGED); + $this->eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), NucleosUserEvents::USER_TIMEZONE_CHANGED); } } diff --git a/src/Resources/config/listeners.php b/src/Resources/config/listeners.php index c557f642..89a88179 100644 --- a/src/Resources/config/listeners.php +++ b/src/Resources/config/listeners.php @@ -14,6 +14,7 @@ use Nucleos\ProfileBundle\EventListener\AlreadyLoggedinListener; use Nucleos\ProfileBundle\EventListener\AuthenticationListener; use Nucleos\ProfileBundle\EventListener\FlashListener; +use Nucleos\ProfileBundle\EventListener\ProfileChangeListener; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Reference; @@ -34,6 +35,12 @@ new Reference('router'), ]) + ->set(ProfileChangeListener::class) + ->tag('kernel.event_subscriber') + ->args([ + new Reference('event_dispatcher'), + ]) + ->set(FlashListener::class) ->tag('kernel.event_subscriber') ->args([