<?php
/**
* @author Quentin CHATELAIN (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\CustomerOutstandingBundle\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__CUSTOMER_OUTSTANDING__ADMIN')) {
$pages = $event->getPages();
$pages[] = [
'id' => 'customer_outstanding_bundle__configuration_settings',
'name' => $this->tr->trans('Customer Outstanding Module', [], 'CustomerOutstandingBundle')
];
$event->setPages($pages);
}
}
}