vendor/bluue/stocks-bundle/src/EventSubscriber/SalesBundle/DocumentTabsEventSubscriber.php line 70

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\StocksBundle\EventSubscriber\SalesBundle;
  9. use App\Services\CheckBundleInstall;
  10. use Bluue\StocksBundle\Event\AccessStockOrderReservedEvent;
  11. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  12. use Symfony\Component\Security\Core\Security;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class DocumentTabsEventSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var TranslatorInterface
  19.      */
  20.     private TranslatorInterface $tr;
  21.     /**
  22.      * @var Security
  23.      */
  24.     private Security $security;
  25.     /**
  26.      * @var EventDispatcherInterface
  27.      */
  28.     private EventDispatcherInterface $eventDispatcher;
  29.     /**
  30.      * @param TranslatorInterface $tr
  31.      * @param Security $security
  32.      * @param EventDispatcherInterface $eventDispatcher
  33.      */
  34.     public function __construct(
  35.         TranslatorInterface $tr,
  36.         Security $security,
  37.         EventDispatcherInterface $eventDispatcher
  38.     ) {
  39.         $this->tr $tr;
  40.         $this->security $security;
  41.         $this->eventDispatcher $eventDispatcher;
  42.     }
  43.     /**
  44.      * @return string[]
  45.      */
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         if (CheckBundleInstall::exist('sales-bundle')) {
  49.             $reflectionClass = new \ReflectionClass('Bluue\SalesBundle\Event\DocumentTabsEvent');
  50.             return [
  51.                 $reflectionClass->getConstant('ORDER_TABS') => 'orderTabs'
  52.             ];
  53.         }
  54.         return [];
  55.     }
  56.     /**
  57.      * @param object $event
  58.      * @return void
  59.      */
  60.     public function orderTabs(object $event)
  61.     {
  62.         $accessStockOrderEvent = new AccessStockOrderReservedEvent(false);
  63.         $this->eventDispatcher->dispatch(
  64.             $accessStockOrderEvent,
  65.             AccessStockOrderReservedEvent::NAME
  66.         );
  67.         if ($accessStockOrderEvent->isAccess() && $this->security->isGranted('ROLE__STOCKS__READ_ONLY')) {
  68.             $event->addTab([
  69.                 'key' => 'stocks_bundle__stock_order_lines_reserved',
  70.                 'name' => $this->tr->trans('Reserved stocks', [], 'StocksBundle'),
  71.                 'icon' => 'fas fa-box-open',
  72.                 'idRequired' => true,
  73.                 'path' => 'stocks_bundle__stock_order_lines_reserved',
  74.                 'layout' => 'view'
  75.             ]);
  76.         }
  77.     }
  78. }