<?php
namespace Customize\EventSubscriber\Mypage;
use Customize\Form\Type\Mypage\UseOrderReturnType;
use Twig\Environment;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormFactoryInterface;
class MypageHistoryEvent implements EventSubscriberInterface
{
/**
* @var Environment
*/
protected $twig;
/**
* @var FormFactoryInterface
*/
protected $formFactory;
public function __construct(
Environment $twig,
FormFactoryInterface $formFactory
) {
$this->twig = $twig;
$this->formFactory = $formFactory;
}
/**
* @param onKernelRequest $event
*/
public function onKernelRequest(RequestEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$route = $event->getRequest()->attributes->get('_route');
if ($route !== 'mypage_history') {
log_info('[CJY:RequestEvent:checkout] Route@mypage_history ではない');
return;
}
$order_no = $event->getRequest()->attributes->get('order_no');
$form = $this->formFactory->create(UseOrderReturnType::class, ['order_no' => $order_no], ['order_no' => $order_no]);
$form = $form->createView();
$this->twig->addGlobal('use_or_form', $form);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [
['onKernelRequest', 10],
]
];
}
}