<?php
/**
* Copyright(c) 2019 SYSTEM_KD
* Date: 2019/06/14
*/
namespace Plugin\MultiCutDx\EventSubscriber;
use Eccube\Event\TemplateEvent;
use Plugin\MultiCutDx\Config\ConfigSetting;
use Plugin\MultiCutDx\Service\PlgConfigService\ConfigService;
use Plugin\MultiCutDx\Service\TwigRenderService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ShoppingEventSubscriber implements EventSubscriberInterface
{
/** @var TwigRenderService */
protected $twigRenderService;
protected $configService;
public function __construct(
TwigRenderService $twigRenderService,
ConfigService $configService
)
{
$this->twigRenderService = $twigRenderService;
$this->configService = $configService;
}
public function onTemplateShopping(TemplateEvent $event)
{
if($this->configService->isKeyBool(ConfigSetting::KEY_MULTI_CUT)) {
$this->twigRenderService->initRenderService($event);
$this->twigRenderService
->insertBuilder()
->find('.ec-orderDelivery__edit')
->eq(0)
->setTargetId('plg_multi_cut')
->setTemplate('<div id="plg_multi_cut" class="ec-orderDelivery__edit"></div>', false)
->setInsertModeReplaceWith();
$this->twigRenderService->addSupportSnippet();
}
}
/**
* 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:
*
* * ['eventName' => 'methodName']
* * ['eventName' => ['methodName', $priority]]
* * ['eventName' => [['methodName1', $priority], ['methodName2']]]
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
'Shopping/index.twig' => ['onTemplateShopping'],
];
}
}