app/Plugin/TabaCMS2/EventListener/NavigationListener.php line 60

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\TabaCMS2\EventListener;
  9. use Eccube\Event\TemplateEvent;
  10. use Eccube\Request\Context;
  11. use Plugin\TabaCMS2\Common\Constants;
  12. use Plugin\TabaCMS2\Repository\TypeRepository;
  13. use Psr\Container\ContainerInterface;
  14. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  15. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  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.      * @var TypeRepository
  32.      */
  33.     private $typeRepo;
  34.     /**
  35.      * コンストラクタ
  36.      */
  37.     public function __construct(
  38.         ContainerInterface $container,
  39.         EventDispatcherInterface $eventDispatcher,
  40.         Context $requestContext,
  41.         TypeRepository $typeRepo
  42.     ) {
  43.         $this->container $container;
  44.         $this->eventDispatcher $eventDispatcher;
  45.         $this->requestContext $requestContext;
  46.         $this->typeRepo $typeRepo;
  47.     }
  48.     /**
  49.      * 管理画面のナビゲーションにtabaのアイコンを追加します。
  50.      *
  51.      * @param ControllerArgumentsEvent $event
  52.      */
  53.     public function onKernelController(ControllerArgumentsEvent $event)
  54.     {
  55.         //
  56.         // 管理画面イベント
  57.         //
  58.         if ($this->requestContext->isAdmin()) {
  59.             //
  60.             // テンプレートイベント
  61.             //
  62.             if ($event->getRequest()->attributes->has('_template')) {
  63.                 $template $event->getRequest()->attributes->get('_template');
  64.                 $this->eventDispatcher->addListener($template->getTemplate(), function (TemplateEvent $templateEvent) {
  65.                     // 管理画面のナビゲーションにtaba app のメニューを差し込みます。
  66.                     $taba $this->container->get(Constants::CONTAINER_KEY_NAME);
  67.                     if (!$taba->get(Constants::PLUGIN_CATEGORY_ID ".menu")) {
  68.                         $templateEvent->addSnippet(Constants::SINIPET_NAV_TABA_APP);
  69.                         $taba->set(Constants::PLUGIN_CATEGORY_ID ".menu",true);
  70.                     }
  71.                     // メニューを差し込みます。
  72.                     $templateEvent->setParameter("type_list",$this->typeRepo->findAll()); // 投稿タイプリストをセット
  73.                     $templateEvent->addSnippet(Constants::SINIPET_NAV);
  74.                 });
  75.             }
  76.         }
  77.     }
  78. }