<?php
/**
* Copyright(c) 2019 SYSTEM_KD
* Date: 2019/07/15
*/
namespace Plugin\PointEx\EventSubscriber;
use Eccube\Event\TemplateEvent;
use Plugin\PointEx\Service\TwigRenderService\TwigRenderService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminShippingEventSubscriber implements EventSubscriberInterface
{
/** @var TwigRenderService */
protected $twigRenderService;
public function __construct(
TwigRenderService $twigRenderService
)
{
$this->twigRenderService = $twigRenderService;
}
public function onTemplateAdminOrderShipping(TemplateEvent $event)
{
$this->twigRenderService->initRenderService($event);
$insertPosition = 5;
// タイトル
$childTitle = $this->twigRenderService
->eachChildBuilder()
->findThis()
->find('thead > tr > th')
->eq($insertPosition)
->targetFindAndIndexKey('#point_ex_bonus_title_', 'shippingIndex')
->setInsertModeAfter();
$this->twigRenderService
->eachBuilder()
->find('[id^=table-form-field_]')
->setEachIndexKey('shippingIndex')
->each($childTitle->build());
// ボーナスポイント
$childItem = $this->twigRenderService
->eachChildBuilder()
->findThis()
->find('td')->eq($insertPosition)
->targetFindAndIndexKey('#point_ex_bonus_[dateKey]_', 'pointExIndex')
->setInsertModeAfter();
$childShopping = $this->twigRenderService
->eachChildBuilder()
->findAndDataKey('#table-form-field_', 'shipping_index')
->find('tbody > tr')
->setEachIndexKey('pointExIndex')
->each($childItem->build());
$this->twigRenderService
->eachBuilder()
->find('.point_ex_bonus')
->each($childShopping->build());
$this->twigRenderService->addSupportSnippet(
'@PointEx/admin/Order/point_ex_order_shipping.twig',
null, true
);
}
/**
* 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 [
'@admin/Order/shipping.twig' => ['onTemplateAdminOrderShipping']
];
}
}