app/Plugin/Schedule/EventSubscriber/AdminCategoryEventSubscriber.php line 59

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2018 SYSTEM_KD
  4.  * Date: 2018/11/25
  5.  */
  6. namespace Plugin\Schedule\EventSubscriber;
  7. use Eccube\Entity\Category;
  8. use Eccube\Event\EccubeEvents;
  9. use Eccube\Event\EventArgs;
  10. use Eccube\Event\TemplateEvent;
  11. use Plugin\Schedule\Service\ScheduleService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Form\FormFactoryInterface;
  14. use Symfony\Component\Form\FormInterface;
  15. class AdminCategoryEventSubscriber implements EventSubscriberInterface
  16. {
  17.     protected $scheduleService;
  18.     protected $formFactory;
  19.     public function __construct(ScheduleService $scheduleServiceFormFactoryInterface $formFactory)
  20.     {
  21.         $this->scheduleService $scheduleService;
  22.         $this->formFactory $formFactory;
  23.     }
  24.     /**
  25.      * カテゴリ登録・更新完了時
  26.      *
  27.      * @param EventArgs $event
  28.      * @throws \Doctrine\ORM\ORMException
  29.      * @throws \Doctrine\ORM\OptimisticLockException
  30.      */
  31.     public function onAdminCategoryIndexComplete(EventArgs $event)
  32.     {
  33.         // カテゴリ登録完了処理
  34.         $Parent $event->getArgument('Parent');
  35.         /** @var Category $TargetCategory */
  36.         $TargetCategory $event->getArgument('TargetCategory');
  37.         /** @var FormInterface $form */
  38.         $form $event->getArgument('form');
  39.         // 関連情報設定
  40.         $this->scheduleService->updateChainScheduleTime($TargetCategory);
  41.     }
  42.     /**
  43.      * カテゴリ
  44.      *
  45.      * @param TemplateEvent $event
  46.      */
  47.     public function onTemplateCategory(TemplateEvent $event)
  48.     {
  49.         // 表示制御追加
  50.         $event->addSnippet('@Schedule/admin/Product/category_ex.twig');
  51.     }
  52.     /**
  53.      * Returns an array of event names this subscriber wants to listen to.
  54.      *
  55.      * The array keys are event names and the value can be:
  56.      *
  57.      *  * The method name to call (priority defaults to 0)
  58.      *  * An array composed of the method name to call and the priority
  59.      *  * An array of arrays composed of the method names to call and respective
  60.      *    priorities, or 0 if unset
  61.      *
  62.      * For instance:
  63.      *
  64.      *  * array('eventName' => 'methodName')
  65.      *  * array('eventName' => array('methodName', $priority))
  66.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  67.      *
  68.      * @return array The event names to listen to
  69.      */
  70.     public static function getSubscribedEvents()
  71.     {
  72.         return [
  73.             EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE => ['onAdminCategoryIndexComplete'],
  74.             '@admin/Product/category.twig' => ['onTemplateCategory']
  75.         ];
  76.     }
  77. }