vendor/bluue/products-bundle/src/EventSubscriber/ConfigureSubMenuSubscriber.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\ProductsBundle\EventSubscriber;
  9. use App\Event\MenuConfigurationPageEvent;
  10. use App\Services\CheckBundleInstall;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ConfigureSubMenuSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var TranslatorInterface
  18.      */
  19.     private TranslatorInterface $tr;
  20.     /**
  21.      * @var Security
  22.      */
  23.     private Security $security;
  24.     /**
  25.      * @var CheckBundleInstall
  26.      */
  27.     private CheckBundleInstall $checkBundleInstall;
  28.     /**
  29.      * @param TranslatorInterface $tr
  30.      * @param Security $security
  31.      * @param CheckBundleInstall $checkBundleInstall
  32.      */
  33.     public function __construct(
  34.         TranslatorInterface $tr,
  35.         Security $security,
  36.         CheckBundleInstall $checkBundleInstall
  37.     ) {
  38.         $this->tr $tr;
  39.         $this->security $security;
  40.         $this->checkBundleInstall $checkBundleInstall;
  41.     }
  42.     /**
  43.      * @return array
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             MenuConfigurationPageEvent::NAME => 'onLoad'
  49.         ];
  50.     }
  51.     /**
  52.      * @param MenuConfigurationPageEvent $event
  53.      * @return void
  54.      */
  55.     public function onLoad(MenuConfigurationPageEvent $event): void
  56.     {
  57.         if ($this->security->isGranted('ROLE__CATALOG__ADMIN')) {
  58.             $pages $event->getPages();
  59.             $subpages = [
  60.                 ['id' => 'products_bundle__configuration_settings'],
  61.                 ['id' => 'products_bundle__configuration_eco_part_group_list'],
  62.                 ['id' => 'products_bundle__configuration_eco_part_list'],
  63.                 ['id' => 'products_bundle__configuration_shared_catalog'],
  64.                 ['id' => 'products_bundle__configuration_attachment_list']
  65.             ];
  66.             if ($this->checkBundleInstall->exist('categories-bundle')) {
  67.                 $subpages[] = ['id' => 'categories_bundle__configuration'];
  68.             }
  69.             $pages[] = [
  70.                 'id' => 'products_bundle__configuration_settings',
  71.                 'name' => $this->tr->trans('Catalog Module', [], 'ProductsBundle'),
  72.                 'subpages' => $subpages
  73.             ];
  74.             $event->setPages($pages);
  75.         }
  76.     }
  77. }