app/Plugin/MultiCutDx/EventSubscriber/ShoppingEventSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/06/14
  5.  */
  6. namespace Plugin\MultiCutDx\EventSubscriber;
  7. use Eccube\Event\TemplateEvent;
  8. use Plugin\MultiCutDx\Config\ConfigSetting;
  9. use Plugin\MultiCutDx\Service\PlgConfigService\ConfigService;
  10. use Plugin\MultiCutDx\Service\TwigRenderService;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class ShoppingEventSubscriber implements EventSubscriberInterface
  13. {
  14.     /** @var TwigRenderService */
  15.     protected $twigRenderService;
  16.     protected $configService;
  17.     public function __construct(
  18.         TwigRenderService $twigRenderService,
  19.         ConfigService $configService
  20.     )
  21.     {
  22.         $this->twigRenderService $twigRenderService;
  23.         $this->configService $configService;
  24.     }
  25.     public function onTemplateShopping(TemplateEvent $event)
  26.     {
  27.         if($this->configService->isKeyBool(ConfigSetting::KEY_MULTI_CUT)) {
  28.             $this->twigRenderService->initRenderService($event);
  29.             $this->twigRenderService
  30.                 ->insertBuilder()
  31.                 ->find('.ec-orderDelivery__edit')
  32.                 ->eq(0)
  33.                 ->setTargetId('plg_multi_cut')
  34.                 ->setTemplate('<div id="plg_multi_cut" class="ec-orderDelivery__edit"></div>'false)
  35.                 ->setInsertModeReplaceWith();
  36.             $this->twigRenderService->addSupportSnippet();
  37.         }
  38.     }
  39.     /**
  40.      * Returns an array of event names this subscriber wants to listen to.
  41.      *
  42.      * The array keys are event names and the value can be:
  43.      *
  44.      *  * The method name to call (priority defaults to 0)
  45.      *  * An array composed of the method name to call and the priority
  46.      *  * An array of arrays composed of the method names to call and respective
  47.      *    priorities, or 0 if unset
  48.      *
  49.      * For instance:
  50.      *
  51.      *  * ['eventName' => 'methodName']
  52.      *  * ['eventName' => ['methodName', $priority]]
  53.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  54.      *
  55.      * @return array The event names to listen to
  56.      */
  57.     public static function getSubscribedEvents()
  58.     {
  59.         return [
  60.             'Shopping/index.twig' => ['onTemplateShopping'],
  61.         ];
  62.     }
  63. }