app/Plugin/TabaFileManager2/TabaFileManagerEvent.php line 82

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\TabaFileManager2;
  9. use Plugin\TabaFileManager2\Common\Constants;
  10. use Eccube\Event\TemplateEvent;
  11. use Eccube\Request\Context;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  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 TabaFileManagerEvent implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var ContainerInterface
  23.      */
  24.     private $container;
  25.     /**
  26.      * @var EntityManagerInterface
  27.      */
  28.     private $entityManager;
  29.     /**
  30.      * @var EventDispatcherInterface
  31.      */
  32.     private $eventDispatcher;
  33.     /**
  34.      * @var Context
  35.      */
  36.     private $requestContext;
  37.     /**
  38.      * @var CsrfTokenManagerInterface
  39.      */
  40.     private $csrfTokenManager;
  41.     public function __construct(
  42.         ContainerInterface $container,
  43.         EntityManagerInterface $entityManager,
  44.         EventDispatcherInterface $eventDispatcher,
  45.         Context $requestContext,
  46.         CsrfTokenManagerInterface $csrfTokenManager
  47.         ) {
  48.             $this->container $container;
  49.             $this->entityManager $entityManager;
  50.             $this->eventDispatcher $eventDispatcher;
  51.             $this->requestContext $requestContext;
  52.             $this->csrfTokenManager $csrfTokenManager;
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      *
  57.      * @return array
  58.      */
  59.     public static function getSubscribedEvents()
  60.     {
  61.         return [
  62.             KernelEvents::CONTROLLER_ARGUMENTS => [['onKernelController'100000000]],
  63.         ];
  64.     }
  65.     /**
  66.      * 管理画面のナビゲーションにtabaのアイコンを追加します。
  67.      *
  68.      * @param ControllerArgumentsEvent $event
  69.      */
  70.     public function onKernelController(ControllerArgumentsEvent $event)
  71.     {
  72.         //
  73.         // 管理画面イベント
  74.         //
  75.         if ($this->requestContext->isAdmin()) {
  76.             //
  77.             // テンプレートイベント
  78.             //
  79.             if ($event->getRequest()->attributes->has('_template')) {
  80.                 $template $event->getRequest()->attributes->get('_template');
  81.                 $this->eventDispatcher->addListener($template->getTemplate(), function (TemplateEvent $templateEvent) {
  82.                     // 管理画面のナビゲーションにtaba app のメニューを差し込みます。
  83.                     $taba $this->container->get(Constants::CONTAINER_KEY_NAME);
  84.                     if (!$taba->get(Constants::PLUGIN_CATEGORY_ID ".menu")) {
  85.                         $templateEvent->addSnippet('@TabaFileManager2/admin/snippet/nav_taba_app.twig');
  86.                         $taba->set(Constants::PLUGIN_CATEGORY_ID ".menu",true);
  87.                     }
  88.                     // メニューを差し込みます。
  89.                     $templateEvent->addSnippet('@TabaFileManager2/admin/snippet/nav.twig');
  90.                 });
  91.             }
  92.         }
  93.     }
  94. }