app/Plugin/TabaFileManager2/EventListener/NavigationListener.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
  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\EventListener;
  9. use Eccube\Event\TemplateEvent;
  10. use Eccube\Request\Context;
  11. use Plugin\TabaFileManager2\Common\Constants;
  12. use Psr\Container\ContainerInterface;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. class NavigationListener
  17. {
  18.     /**
  19.      * @var ContainerInterface
  20.      */
  21.     private $container;
  22.     /**
  23.      * @var EventDispatcherInterface
  24.      */
  25.     private $eventDispatcher;
  26.     /**
  27.      * @var Context
  28.      */
  29.     private $requestContext;
  30.     /**
  31.      * コンストラクタ
  32.      */
  33.     public function __construct(
  34.         ContainerInterface $container,
  35.         EventDispatcherInterface $eventDispatcher,
  36.         Context $requestContext
  37.     ) {
  38.         $this->container $container;
  39.         $this->eventDispatcher $eventDispatcher;
  40.         $this->requestContext $requestContext;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      *
  45.      * @return array
  46.      */
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [
  50.             KernelEvents::CONTROLLER_ARGUMENTS => [['onKernelController'100000000]],
  51.         ];
  52.     }
  53.     /**
  54.      * 管理画面のナビゲーションにtabaのアイコンを追加します。
  55.      *
  56.      * @param ControllerArgumentsEvent $event
  57.      */
  58.     public function onKernelController(ControllerArgumentsEvent $event)
  59.     {
  60.         //
  61.         // 管理画面イベント
  62.         //
  63.         if ($this->requestContext->isAdmin()) {
  64.             //
  65.             // テンプレートイベント
  66.             //
  67.             if ($event->getRequest()->attributes->has('_template')) {
  68.                 $template $event->getRequest()->attributes->get('_template');
  69.                 $this->eventDispatcher->addListener($template->getTemplate(), function (TemplateEvent $templateEvent) {
  70.                     // 管理画面のナビゲーションにtaba app のメニューを差し込みます。
  71.                     $taba $this->container->get(Constants::CONTAINER_KEY_NAME);
  72.                     if (!$taba->get(Constants::PLUGIN_CATEGORY_ID ".menu")) {
  73.                         $templateEvent->addSnippet('@TabaFileManager2/admin/snippet/nav_taba_app.twig');
  74.                         $taba->set(Constants::PLUGIN_CATEGORY_ID ".menu",true);
  75.                     }
  76.                     // メニューを差し込みます。
  77.                     $templateEvent->addSnippet('@TabaFileManager2/admin/snippet/nav.twig');
  78.                 });
  79.             }
  80.         }
  81.     }
  82. }