<?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\TabaCMS2\EventListener;
use Eccube\Event\TemplateEvent;
use Eccube\Request\Context;
use Plugin\TabaCMS2\Common\Constants;
use Plugin\TabaCMS2\Repository\TypeRepository;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
class NavigationListener
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var Context
*/
private $requestContext;
/**
* @var TypeRepository
*/
private $typeRepo;
/**
* コンストラクタ
*/
public function __construct(
ContainerInterface $container,
EventDispatcherInterface $eventDispatcher,
Context $requestContext,
TypeRepository $typeRepo
) {
$this->container = $container;
$this->eventDispatcher = $eventDispatcher;
$this->requestContext = $requestContext;
$this->typeRepo = $typeRepo;
}
/**
* 管理画面のナビゲーションに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->setParameter("type_list",$this->typeRepo->findAll()); // 投稿タイプリストをセット
$templateEvent->addSnippet(Constants::SINIPET_NAV);
});
}
}
}
}