- <?php
- /*
-  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
-  *
-  * For the full copyright and license information, please view the LICENSE
-  * file that was distributed with this source code.
-  */
- namespace Plugin\TabaBannerManager2\EventListener;
- use Eccube\Event\TemplateEvent;
- use Eccube\Request\Context;
- use Plugin\TabaBannerManager2\Common\Constants;
- use Psr\Container\ContainerInterface;
- use Symfony\Component\EventDispatcher\EventDispatcherInterface;
- use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- class NavigationListener
- {
-     /**
-      * @var ContainerInterface
-      */
-     private $container;
-     /**
-      * @var EventDispatcherInterface
-      */
-     private $eventDispatcher;
-     /**
-      * @var Context
-      */
-     private $requestContext;
-     /**
-      * コンストラクタ
-      */
-     public function __construct(
-         ContainerInterface $container,
-         EventDispatcherInterface $eventDispatcher,
-         Context $requestContext
-     ) {
-         $this->container = $container;
-         $this->eventDispatcher = $eventDispatcher;
-         $this->requestContext = $requestContext;
-     }
-     /**
-      * 管理画面のナビゲーションにtabaのアイコンを追加します。
-      *
-      * @param ControllerArgumentsEvent $event
-      */
-     public function onKernelController(ControllerArgumentsEvent $event)
-     {
-         //
-         // 管理画面イベント
-         //
-         if ($this->requestContext->isAdmin()) {
-             //
-             // テンプレートイベント
-             //
-             if ($event->getRequest()->attributes->has('_template')) {
-                 $template = $event->getRequest()->attributes->get('_template');
-                 $this->eventDispatcher->addListener($template->getTemplate(), function (TemplateEvent $templateEvent) {
-                     // 管理画面のナビゲーションにtaba app のメニューを差し込みます。
-                     $taba = $this->container->get(Constants::CONTAINER_KEY_NAME);
-                     if (!$taba->get(Constants::PLUGIN_CATEGORY_ID . ".menu")) {
-                         $templateEvent->addSnippet(Constants::SINIPET_NAV_TABA_APP);
-                         $taba->set(Constants::PLUGIN_CATEGORY_ID . ".menu",true);
-                     }
-                     // メニューを差し込みます。
-                     $templateEvent->addSnippet(Constants::SINIPET_NAV);
-                 });
-             }
-         }
-     }
- }
-