<?php
declare(strict_types=1);
namespace Bluue\CrmBundle\EventSubscriber;
use App\Services\CheckBundleInstall;
use ReflectionClass;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(TranslatorInterface $tr, Security $security)
{
$this->tr = $tr;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('statistics-bundle')) {
$reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
return [
$reflectionClass->getConstant('NAME') => 'onLoad'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function onLoad(object $event): void
{
if (!$this->security->isGranted('ROLE__CRM__READ_ONLY')) {
return;
}
$pages = $event->getPages();
$pages[] = [
'id' => 'crm_bundle__statistics',
'name' => $this->tr->trans('CRM', [], 'CrmBundle')
];
$event->setPages($pages);
}
}