<?php
declare(strict_types=1);
namespace Bluue\Cx3Bundle\EventSubscriber;
use App\Event\MenuConfigurationPageEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureSubMenuSubscriber 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 string[]
*/
public static function getSubscribedEvents(): array
{
return [
MenuConfigurationPageEvent::NAME => 'onLoad'
];
}
/**
* @param MenuConfigurationPageEvent $event
* @return void
*/
public function onLoad(MenuConfigurationPageEvent $event): void
{
if ($this->security->isGranted('ROLE_ADMIN')) {
$pages = $event->getPages();
$pages[] = [
'id' => 'cx3_bundle__configuration_settings',
'name' => $this->tr->trans('3CX Module', [], 'Cx3Bundle'),
'subpages' => [
['id' => 'cx3_bundle__configuration_settings']
]
];
$event->setPages($pages);
}
}
}