vendor/bluue/labels-bundle/src/EventSubscriber/ProductsBundle/ConfigureProductMenuSubscriber.php line 70

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (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\LabelsBundle\EventSubscriber\ProductsBundle;
  9. use ReflectionClass;
  10. use App\Services\CheckBundleInstall;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class ConfigureProductMenuSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var TranslatorInterface
  19.      */
  20.     private TranslatorInterface $tr;
  21.     /**
  22.      * @var Security
  23.      */
  24.     private Security $security;
  25.     /**
  26.      * @var RequestStack
  27.      */
  28.     private RequestStack $requestStack;
  29.     /**
  30.      * @param TranslatorInterface $tr
  31.      * @param Security $security
  32.      * @param RequestStack $requestStack
  33.      */
  34.     public function __construct(
  35.         TranslatorInterface $tr,
  36.         Security $security,
  37.         RequestStack $requestStack
  38.     ) {
  39.         $this->tr $tr;
  40.         $this->security $security;
  41.         $this->requestStack $requestStack;
  42.     }
  43.     /**
  44.      * @return array
  45.      */
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         if (CheckBundleInstall::exist('products-bundle')) {
  49.             $reflectionClass = new ReflectionClass('Bluue\ProductsBundle\Event\ConfigurationProductMenuEvent');
  50.             return [
  51.                 $reflectionClass->getConstant('NAME') => 'onLoad'
  52.             ];
  53.         }
  54.         return [];
  55.     }
  56.     /**
  57.      * @param object $event
  58.      * @return void
  59.      */
  60.     public function onLoad(object $event): void
  61.     {
  62.         $productId $this->requestStack->getMainRequest()->attributes->get('id');
  63.         if (!$productId || !$this->security->isGranted('ROLE__LABELS__SMALL_ADMIN')) {
  64.             return;
  65.         }
  66.         $pages $event->getPages();
  67.         $pages[] = [
  68.             'path' => 'labels_bundle__product_elements',
  69.             'product_id_required' => true,
  70.             'href' => 'labels',
  71.             'name' => $this->tr->trans('Labels', [], 'LabelsBundle')
  72.         ];
  73.         $event->setPages($pages);
  74.     }
  75. }