<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\CategoriesBundle\EventSubscriber;
use Bluue\ProductsBundle\Event\ConfigurationProductMenuConfigurationEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureProductMenuConfigurationSubscriber 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 [
ConfigurationProductMenuConfigurationEvent::NAME => 'onLoad'
];
}
/**
* @param ConfigurationProductMenuConfigurationEvent $event
* @return void
*/
public function onLoad(ConfigurationProductMenuConfigurationEvent $event): void
{
if (!$this->security->isGranted('ROLE__CATALOG__ADMIN')) {
return;
}
$pages = $event->getPages();
$pages[] = [
'id' => 'categories_bundle__configuration',
'name' => $this->tr->trans('Category configuration', [], 'CategoriesBundle')
];
$event->setPages($pages);
}
}