<?php
/**
* @author Léo BANNHOLTZER (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\SalesBundle\EventSubscriber\ProductsBundle;
use Bluue\ProductsBundle\Event\ConfigurationProductMenuEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureProductMenuSubscriber 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 [
ConfigurationProductMenuEvent::NAME => 'onLoad'
];
}
/**
* @param ConfigurationProductMenuEvent $event
* @return void
*/
public function onLoad(ConfigurationProductMenuEvent $event): void
{
if (!$this->security->isGranted('ROLE__SALES__READ_ONLY')) {
return;
}
$pages = $event->getPages();
$pages[] = [
'path' => 'sales_bundle__products_bundle__sales_history',
'product_id_required' => true,
'href' => 'sales',
'name' => $this->tr->trans('Sales', [], 'SalesBundle')
];
$event->setPages($pages);
}
}