vendor/bluue/crm-bundle/src/EventSubscriber/ConfigureStatisticsMenuConfigurationSubscriber.php line 53

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\CrmBundle\EventSubscriber;
  4. use App\Services\CheckBundleInstall;
  5. use ReflectionClass;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var TranslatorInterface
  13.      */
  14.     private TranslatorInterface $tr;
  15.     /**
  16.      * @var Security
  17.      */
  18.     private Security $security;
  19.     /**
  20.      * @param TranslatorInterface $tr
  21.      * @param Security $security
  22.      */
  23.     public function __construct(TranslatorInterface $trSecurity $security)
  24.     {
  25.         $this->tr $tr;
  26.         $this->security $security;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         if (CheckBundleInstall::exist('statistics-bundle')) {
  34.             $reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
  35.             return [
  36.                 $reflectionClass->getConstant('NAME') => 'onLoad'
  37.             ];
  38.         }
  39.         return [];
  40.     }
  41.     /**
  42.      * @param object $event
  43.      * @return void
  44.      */
  45.     public function onLoad(object $event): void
  46.     {
  47.         if (!$this->security->isGranted('ROLE__CRM__READ_ONLY')) {
  48.             return;
  49.         }
  50.         $pages $event->getPages();
  51.         $pages[] = [
  52.             'id' => 'crm_bundle__statistics',
  53.             'name' => $this->tr->trans('CRM', [], 'CrmBundle')
  54.         ];
  55.         $event->setPages($pages);
  56.     }
  57. }