vendor/ezsystems/ezplatform-user/src/lib/EventListener/UserMenuListener.php line 43

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace EzSystems\EzPlatformUser\EventListener;
  8. use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
  9. use JMS\TranslationBundle\Model\Message;
  10. use JMS\TranslationBundle\Translation\TranslationContainerInterface;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. class UserMenuListener implements EventSubscriberInterfaceTranslationContainerInterface
  14. {
  15.     public const ITEM_CHANGE_PASSWORD 'user__change_password';
  16.     /** @var \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface */
  17.     private $tokenStorage;
  18.     /**
  19.      * @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage
  20.      */
  21.     public function __construct(TokenStorageInterface $tokenStorage)
  22.     {
  23.         $this->tokenStorage $tokenStorage;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [ConfigureMenuEvent::USER_MENU => 'onUserMenuConfigure'];
  31.     }
  32.     /**
  33.      * @param \EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent $event
  34.      */
  35.     public function onUserMenuConfigure(ConfigureMenuEvent $event): void
  36.     {
  37.         $menu $event->getMenu();
  38.         $token $this->tokenStorage->getToken();
  39.         if (null !== $token && is_object($token->getUser())) {
  40.             $menu->addChild(
  41.                 self::ITEM_CHANGE_PASSWORD,
  42.                 [
  43.                     'route' => 'ezplatform.user_profile.change_password',
  44.                     'extras' => [
  45.                         'translation_domain' => 'menu',
  46.                         'orderNumber' => 10,
  47.                     ],
  48.                 ]
  49.             );
  50.         }
  51.     }
  52.     /**
  53.      * @return \JMS\TranslationBundle\Model\Message[]
  54.      */
  55.     public static function getTranslationMessages(): array
  56.     {
  57.         return [
  58.             (new Message(self::ITEM_CHANGE_PASSWORD'menu'))->setDesc('Change password'),
  59.         ];
  60.     }
  61. }