<?php
/*
* Copyright (C) 2018 SPREAD WORKS Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\TabaFileManager2;
use Plugin\TabaFileManager2\Common\Constants;
use Eccube\Event\TemplateEvent;
use Eccube\Request\Context;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Doctrine\ORM\EntityManagerInterface;
class TabaFileManagerEvent implements EventSubscriberInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var Context
*/
private $requestContext;
/**
* @var CsrfTokenManagerInterface
*/
private $csrfTokenManager;
public function __construct(
ContainerInterface $container,
EntityManagerInterface $entityManager,
EventDispatcherInterface $eventDispatcher,
Context $requestContext,
CsrfTokenManagerInterface $csrfTokenManager
) {
$this->container = $container;
$this->entityManager = $entityManager;
$this->eventDispatcher = $eventDispatcher;
$this->requestContext = $requestContext;
$this->csrfTokenManager = $csrfTokenManager;
}
/**
* {@inheritdoc}
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => [['onKernelController', 100000000]],
];
}
/**
* 管理画面のナビゲーションに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('@TabaFileManager2/admin/snippet/nav_taba_app.twig');
$taba->set(Constants::PLUGIN_CATEGORY_ID . ".menu",true);
}
// メニューを差し込みます。
$templateEvent->addSnippet('@TabaFileManager2/admin/snippet/nav.twig');
});
}
}
}
}