<?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\ShipmentsBundle\EventSubscriber\SalesBundle;
use Symfony\Component\Security\Core\Security;
use Bluue\SalesBundle\Event\DocumentTabsEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DocumentTabsEventSubscriber 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 [
DocumentTabsEvent::ORDER_TABS => 'onLoad'
];
}
/**
* @param DocumentTabsEvent $event
* @return void
*/
public function onLoad(DocumentTabsEvent $event): void
{
if (!$this->security->isGranted('ROLE__SHIPMENTS__READ_ONLY')) {
return;
}
$event->addTab([
'key' => 'shipments_bundle__edit_shipment',
'name' => $this->tr->trans('Shipment', [], 'ShipmentsBundle'),
'icon' => 'fas fa-shipping-fast',
'idRequired' => true,
'path' => 'shipments_bundle__edit_shipment'
]);
}
}