vendor/coreshop/pimcore-bundle/EventListener/AdminJavascriptListener.php line 63

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * CoreShop
  5.  *
  6.  * This source file is available under two different licenses:
  7.  *  - GNU General Public License version 3 (GPLv3)
  8.  *  - CoreShop Commercial License (CCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) CoreShop GmbH (https://www.coreshop.org)
  13.  * @license    https://www.coreshop.org/license     GPLv3 and CCL
  14.  *
  15.  */
  16. namespace CoreShop\Bundle\PimcoreBundle\EventListener;
  17. use Pimcore\Event\BundleManager\PathsEvent;
  18. use Pimcore\Event\BundleManagerEvents;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. final class AdminJavascriptListener implements EventSubscriberInterface
  21. {
  22.     public function __construct(
  23.         private array $jsResources,
  24.         private array $editmodeJsResources,
  25.         private array $cssResources,
  26.         private array $editmodeCssResources,
  27.     ) {
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             BundleManagerEvents::JS_PATHS => 'getAdminJavascript',
  33.             BundleManagerEvents::CSS_PATHS => 'getAdminCss',
  34.             BundleManagerEvents::EDITMODE_JS_PATHS => 'getEditmodeAdminJavascript',
  35.             BundleManagerEvents::EDITMODE_CSS_PATHS => 'getEditmodeAdminCSS',
  36.         ];
  37.     }
  38.     public function getAdminJavascript(PathsEvent $event): void
  39.     {
  40.         if (count($this->jsResources) === 0) {
  41.             return;
  42.         }
  43.         $event->setPaths(array_merge($event->getPaths(), $this->jsResources));
  44.     }
  45.     public function getAdminCss(PathsEvent $event): void
  46.     {
  47.         if (count($this->cssResources) === 0) {
  48.             return;
  49.         }
  50.         $event->setPaths(array_merge($event->getPaths(), $this->cssResources));
  51.     }
  52.     public function getEditmodeAdminJavascript(PathsEvent $event): void
  53.     {
  54.         if (count($this->editmodeJsResources) === 0) {
  55.             return;
  56.         }
  57.         $event->setPaths(array_merge($event->getPaths(), $this->editmodeJsResources));
  58.     }
  59.     public function getEditmodeAdminCSS(PathsEvent $event): void
  60.     {
  61.         if (count($this->editmodeCssResources) === 0) {
  62.             return;
  63.         }
  64.         $event->setPaths(array_merge($event->getPaths(), $this->editmodeCssResources));
  65.     }
  66. }