<?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\ShipmentsPictureBundle\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 array
*/
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' => 'shipments_picture_bundle__configuration',
'name' => $this->tr->trans('Shipments Picture Module', [], 'ShipmentsPictureBundle')
];
$event->setPages($pages);
}
}
}