<?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\SuppliersOrdersBundle\EventSubscriber;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\RequestStack;
use Bluue\SuppliersBundle\Event\SupplierViewTabsEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SupplierViewTabsSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var RequestStack
*/
protected RequestStack $requestStack;
/**
* @var Security
*/
protected Security $security;
/**
* @param RequestStack $requestStack
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(
RequestStack $requestStack,
TranslatorInterface $tr,
Security $security
) {
$this->requestStack = $requestStack;
$this->tr = $tr;
$this->security = $security;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
SupplierViewTabsEvent::NAME => 'onLoad'
];
}
/**
* @param SupplierViewTabsEvent $event
* @return void
*/
public function onLoad(SupplierViewTabsEvent $event): void
{
if (!$this->security->isGranted('ROLE__SUPPLIERS__READ_ONLY')) {
return;
}
$tabs = $event->getPages();
$newTabs = [
[
'path' => 'suppliers_orders_bundle__supplier_view_orders',
'id_required' => true,
'name' => $this->tr->trans('Suppliers orders', [], 'SuppliersOrdersBundle')
],
[
'path' => 'suppliers_orders_bundle__supplier_view_waiting_products',
'id_required' => true,
'name' => $this->tr->trans('Waiting products', [], 'SuppliersOrdersBundle')
]
];
$event->setPages(array_merge($tabs, $newTabs));
}
}