vendor/bluue/projects-bundle/src/EventSubscriber/ConfigurationProfileMenuSubscriber.php line 54

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\ProjectsBundle\EventSubscriber;
  9. use App\Event\ConfigurationProfileMenuEvent;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class ConfigurationProfileMenuSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var TranslatorInterface
  17.      */
  18.     private TranslatorInterface $tr;
  19.     /**
  20.      * @var Security
  21.      */
  22.     private Security $security;
  23.     /**
  24.      * @param TranslatorInterface $tr
  25.      * @param Security $security
  26.      */
  27.     public function __construct(TranslatorInterface $trSecurity $security)
  28.     {
  29.         $this->tr $tr;
  30.         $this->security $security;
  31.     }
  32.     /**
  33.      * @return array
  34.      */
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             ConfigurationProfileMenuEvent::NAME => 'onLoad'
  39.         ];
  40.     }
  41.     /**
  42.      * @param ConfigurationProfileMenuEvent $event
  43.      * @return void
  44.      */
  45.     public function onLoad(ConfigurationProfileMenuEvent $event): void
  46.     {
  47.         if (!$this->security->isGranted('ROLE__PROJECTS__READ_ONLY')) {
  48.             return;
  49.         }
  50.         $pages $event->getPages();
  51.         $pages[] = [
  52.             'path' => 'projects_bundle__profile_form',
  53.             'user_id_required' => false,
  54.             'name' => $this->tr->trans('Projects', [], 'ProjectsBundle')
  55.         ];
  56.         $event->setPages($pages);
  57.     }
  58. }