vendor/bluue/categories-bundle/src/EventSubscriber/ConfigureProductMenuSubscriber.php line 65

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\CategoriesBundle\EventSubscriber;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Bluue\ProductsBundle\Event\ConfigurationProductMenuEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ConfigureProductMenuSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var TranslatorInterface
  18.      */
  19.     private TranslatorInterface $tr;
  20.     /**
  21.      * @var Security
  22.      */
  23.     private Security $security;
  24.     /**
  25.      * @var RequestStack
  26.      */
  27.     private RequestStack $requestStack;
  28.     /**
  29.      * @param TranslatorInterface $tr
  30.      * @param Security $security
  31.      * @param RequestStack $requestStack
  32.      */
  33.     public function __construct(
  34.         TranslatorInterface $tr,
  35.         Security $security,
  36.         RequestStack $requestStack
  37.     ) {
  38.         $this->tr $tr;
  39.         $this->security $security;
  40.         $this->requestStack $requestStack;
  41.     }
  42.     /**
  43.      * @return array
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             ConfigurationProductMenuEvent::NAME => 'onLoad'
  49.         ];
  50.     }
  51.     /**
  52.      * @param ConfigurationProductMenuEvent $event
  53.      * @return void
  54.      */
  55.     public function onLoad(ConfigurationProductMenuEvent $event): void
  56.     {
  57.         $productId $this->requestStack->getMainRequest()->attributes->get('id');
  58.         if (!$productId || !$this->security->isGranted('ROLE__CATALOG__SMALL_ADMIN')) {
  59.             return;
  60.         }
  61.         $pages $event->getPages();
  62.         $pages[] = [
  63.             'path' => 'categories_bundle__category_product_list',
  64.             'product_id_required' => true,
  65.             'href' => 'categories',
  66.             'name' => $this->tr->trans('Categories', [], 'CategoriesBundle')
  67.         ];
  68.         $event->setPages($pages);
  69.     }
  70. }