app/Plugin/TabaHtmlEditor2/TabaHtmlEditorEvent.php line 85

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) 2018 SPREAD WORKS Inc.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Plugin\TabaHtmlEditor2;
  9. // use Plugin\TabaHtmlEditor2\Common\Constants;
  10. use Plugin\TabaHtmlEditor2\Common\UserConfig;
  11. use Eccube\Event\TemplateEvent;
  12. use Eccube\Request\Context;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  17. use Symfony\Component\HttpKernel\KernelEvents;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. class TabaHtmlEditorEvent implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var ContainerInterface
  23.      */
  24.     private $container;
  25.     /**
  26.      * @var EntityManagerInterface
  27.      */
  28.     private $entityManager;
  29.     /**
  30.      *
  31.      * @var EventDispatcherInterface
  32.      */
  33.     private $eventDispatcher;
  34.     /**
  35.      *
  36.      * @var Context
  37.      */
  38.     private $requestContext;
  39.     /**
  40.      * @var array
  41.      */
  42.     private $eccubeConfig;
  43.     public function __construct(
  44.         ContainerInterface $container,
  45.         EntityManagerInterface $entityManager,
  46.         EventDispatcherInterface $eventDispatcher,
  47.         Context $requestContext)
  48.     {
  49.         $this->container $container;
  50.         $this->entityManager $entityManager;
  51.         $this->eventDispatcher $eventDispatcher;
  52.         $this->requestContext $requestContext;
  53.     }
  54.     /**
  55.      *
  56.      * {@inheritdoc}
  57.      *
  58.      * @return array
  59.      */
  60.     public static function getSubscribedEvents()
  61.     {
  62.         return [
  63.             KernelEvents::CONTROLLER_ARGUMENTS => [
  64.                 [
  65.                     'onKernelControllerArguments',
  66.                     100000000
  67.                 ],
  68.             ]
  69.         ];
  70.     }
  71.     /**
  72.      * @param ControllerArgumentsEvent $event
  73.      */
  74.     public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
  75.     {
  76.         //
  77.         // 管理画面イベント
  78.         //
  79.         if ($this->requestContext->isAdmin()) {
  80.             //
  81.             // テンプレートイベント
  82.             //
  83.             if ($event->getRequest()->attributes->has('_template') && ($template $event->getRequest()->attributes->get('_template'))) {
  84.                 if ($template->getTemplate()) {
  85.                     $templateName str_replace('@','',$template->getTemplate());
  86.                     $userConfig UserConfig::getInstance();
  87.                     if (($pages $userConfig->get('page'))) {
  88.                         foreach ($pages as $page) {
  89.                             if (
  90.                                 $page
  91.                                 && $page['template']
  92.                                 && $templateName == str_replace('@','',$page['template'])
  93.                                 && isset($page['selector'])
  94.                             ) {
  95.                                 $this->eventDispatcher->addListener($template->getTemplate(), function (TemplateEvent $templateEvent) use ($page) {
  96.                                     if (!is_array($page['selector'])) $page['selector'] = [$page['selector']];
  97.                                     $templateEvent->setParameter("selectors",$page['selector']);
  98.                                     $templateEvent->addSnippet('@TabaHtmlEditor2/admin/snippet/editor.twig');
  99.                                     $templateEvent->addAsset('@TabaHtmlEditor2/admin/snippet/asset.twig');
  100.                                 });
  101.                                 break;
  102.                             }
  103.                         }
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     }
  109. }