vendor/bluue/pim-bundle/src/EventSubscriber/AdditionalJavascriptsSubscriber.php line 52

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\PimBundle\EventSubscriber;
  9. use App\Event\AdditionalJavascriptsEvent;
  10. use App\Services\CheckBundleInstall;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Routing\RouterInterface;
  13. use Symfony\Component\Security\Core\Security;
  14. class AdditionalJavascriptsSubscriber implements EventSubscriberInterface
  15. {
  16.     private RouterInterface $router;
  17.     /**
  18.      * @var Security
  19.      */
  20.     private Security $security;
  21.     /**
  22.      * @param RouterInterface $router
  23.      * @param Security $security
  24.      */
  25.     public function __construct(RouterInterface $routerSecurity $security)
  26.     {
  27.         $this->router $router;
  28.         $this->security $security;
  29.     }
  30.     /**
  31.      * @return string[]
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             AdditionalJavascriptsEvent::NAME => 'onLoad'
  37.         ];
  38.     }
  39.     /**
  40.      * @param AdditionalJavascriptsEvent $event
  41.      * @return void
  42.      */
  43.     public function onLoad(AdditionalJavascriptsEvent $event): void
  44.     {
  45.         $javascripts = [
  46.             [
  47.                 'entry' => 'pim_bundle',
  48.                 'controllers' => [
  49.                     [
  50.                         'name' => 'pim--edit-fields',
  51.                         'routes' => [
  52.                             'pim_bundle__mass_management'
  53.                         ]
  54.                     ],
  55.                     [
  56.                         'name' => 'pim--calc-price-with-margin',
  57.                         'routes' => [
  58.                             'pim_bundle__mass_management'
  59.                         ]
  60.                     ]
  61.                 ]
  62.             ]
  63.         ];
  64.         if (CheckBundleInstall::exist('categories-bundle')) {
  65.             $javascripts[0]['controllers'][] = [
  66.                 'name' => 'pim--manage-categories',
  67.                 'routes' => [
  68.                     'pim_bundle__mass_management'
  69.                 ],
  70.             ];
  71.         }
  72.         if ($this->security->isGranted('ROLE__PIM__ADMIN')) {
  73.             $javascripts[0]['controllers'][] = [
  74.                 'name' => 'pim--sequential-modification',
  75.                 'routes' => [
  76.                     'products_bundle__product_sheet'
  77.                 ],
  78.                 'options' => [
  79.                     'data-sequential-modification-url' => $this->router->generate(
  80.                         'pim_bundle__sequential_modification_check'
  81.                     )
  82.                 ]
  83.             ];
  84.         }
  85.         $event->addJavascripts($javascripts);
  86.     }
  87. }