<?php
/**
* Copyright(c) 2018 SYSTEM_KD
* Date: 2018/11/25
*/
namespace Plugin\Schedule\EventSubscriber;
use Eccube\Entity\Category;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Event\TemplateEvent;
use Plugin\Schedule\Service\ScheduleService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
class AdminCategoryEventSubscriber implements EventSubscriberInterface
{
protected $scheduleService;
protected $formFactory;
public function __construct(ScheduleService $scheduleService, FormFactoryInterface $formFactory)
{
$this->scheduleService = $scheduleService;
$this->formFactory = $formFactory;
}
/**
* カテゴリ登録・更新完了時
*
* @param EventArgs $event
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function onAdminCategoryIndexComplete(EventArgs $event)
{
// カテゴリ登録完了処理
$Parent = $event->getArgument('Parent');
/** @var Category $TargetCategory */
$TargetCategory = $event->getArgument('TargetCategory');
/** @var FormInterface $form */
$form = $event->getArgument('form');
// 関連情報設定
$this->scheduleService->updateChainScheduleTime($TargetCategory);
}
/**
* カテゴリ
*
* @param TemplateEvent $event
*/
public function onTemplateCategory(TemplateEvent $event)
{
// 表示制御追加
$event->addSnippet('@Schedule/admin/Product/category_ex.twig');
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE => ['onAdminCategoryIndexComplete'],
'@admin/Product/category.twig' => ['onTemplateCategory']
];
}
}