vendor/bluue/shipments-bundle/src/EventSubscriber/SalesBundle/DocumentTabsEventSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Quentin CHATELAIN (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\ShipmentsBundle\EventSubscriber\SalesBundle;
  9. use Symfony\Component\Security\Core\Security;
  10. use Bluue\SalesBundle\Event\DocumentTabsEvent;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class DocumentTabsEventSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var TranslatorInterface
  17.      */
  18.     private TranslatorInterface $tr;
  19.     /**
  20.      * @var Security
  21.      */
  22.     private Security $security;
  23.     /**
  24.      * @param TranslatorInterface $tr
  25.      * @param Security $security
  26.      */
  27.     public function __construct(
  28.         TranslatorInterface $tr,
  29.         Security $security
  30.     ) {
  31.         $this->tr $tr;
  32.         $this->security $security;
  33.     }
  34.     /**
  35.      * @return array
  36.      */
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             DocumentTabsEvent::ORDER_TABS => 'onLoad'
  41.         ];
  42.     }
  43.     /**
  44.      * @param DocumentTabsEvent $event
  45.      * @return void
  46.      */
  47.     public function onLoad(DocumentTabsEvent $event): void
  48.     {
  49.         if (!$this->security->isGranted('ROLE__SHIPMENTS__READ_ONLY')) {
  50.             return;
  51.         }
  52.         $event->addTab([
  53.             'key' => 'shipments_bundle__edit_shipment',
  54.             'name' => $this->tr->trans('Shipment', [], 'ShipmentsBundle'),
  55.             'icon' => 'fas fa-shipping-fast',
  56.             'idRequired' => true,
  57.             'path' => 'shipments_bundle__edit_shipment'
  58.         ]);
  59.     }
  60. }