src/EventSubscriber/UserDetailsSubscriber.php line 40
<?php/** This file is part of the Tabler-Bundle demo.* Copyright 2021 Kevin Papst - www.kevinpapst.de** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/namespace App\EventSubscriber;use App\Entity\User;use KevinPapst\TablerBundle\Event\UserDetailsEvent;use KevinPapst\TablerBundle\Model\MenuItemModel;use KevinPapst\TablerBundle\Model\UserModel;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Bundle\SecurityBundle\Security;use Symfony\Component\Security\Core\User\InMemoryUser;use Symfony\Contracts\Translation\TranslatorInterface;class UserDetailsSubscriber implements EventSubscriberInterface{private $security;private $translator;public function __construct(Security $security,TranslatorInterface $translator){$this->security = $security;$this->translator = $translator;}public static function getSubscribedEvents(): array{return [UserDetailsEvent::class => ['onShowUser', 100],];}public function onShowUser(UserDetailsEvent $event): void{if (null === $this->security->getUser()) {return;}/* @var $myUser User */$myUser = $this->security->getUser();$user = new UserModel($myUser->getId(), $myUser->getUserIdentifier());$user->setId($myUser->getId());$user->setName($myUser->getFirstname().' '.$myUser->getLastname());//$user->setTitle('demo usedfdsfdsr');$user->setTitle($this->translator->trans('lawOfficeName',[],'translation').': '.$myUser->getLawOffice()->getLawOfficeName());$user->setAvatar('img/default_avatar.png');$event->setUser($user);$event->addLink(new MenuItemModel('profile', $this->translator->trans('My profile',[],'translation'), 'app_user_show',['id'=>$myUser->getId()],'fa fa-address-card'));}}