Skip to content

Commit

Permalink
Update locale settings after saving the profile
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jan 11, 2020
1 parent 80e91aa commit b3a63c7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/EventListener/ProfileChangeListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the NucleosProfileBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\ProfileBundle\EventListener;

use Nucleos\ProfileBundle\NucleosProfileEvents;
use Nucleos\UserBundle\Event\FilterUserResponseEvent;
use Nucleos\UserBundle\Event\UserEvent;
use Nucleos\UserBundle\NucleosUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

final class ProfileChangeListener implements EventSubscriberInterface
{
/**
* @return array<string, string>
*/
public static function getSubscribedEvents(): array
{
return [
NucleosProfileEvents::PROFILE_EDIT_COMPLETED => 'profileChanged',
];
}

public function profileChanged(FilterUserResponseEvent $event, string $eventName, EventDispatcherInterface $eventDispatcher): 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);
}
}

0 comments on commit b3a63c7

Please sign in to comment.