<?php
declare(strict_types=1);
namespace Bluue\AdelyaBundle\EventSubscriber;
use App\Event\MenuConfigurationPageEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigurationMenuSubscriber implements EventSubscriberInterface
{
/**
* @var Security
*/
private Security $security;
/**
* @param Security $security
*/
public function __construct(
Security $security
) {
$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__CASH_REGISTER__ADMIN')) {
$pages = $event->getPages();
foreach ($pages as $key => $value) {
if ($value['id'] == 'cash_register_bundle__configuration_settings') {
$pages[$key]['subpages'][] = ['id' => 'adelya_bundle__configuration_settings'];
}
}
$event->setPages($pages);
}
}
}