app/Customize/EventSubscriber/Mypage/MypageHistoryEvent.php line 36

Open in your IDE?
  1. <?php
  2. namespace Customize\EventSubscriber\Mypage;
  3. use Customize\Form\Type\Mypage\UseOrderReturnType;
  4. use Twig\Environment;
  5. use Symfony\Component\HttpKernel\Event\RequestEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Form\FormFactoryInterface;
  9. class MypageHistoryEvent implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var Environment
  13.      */
  14.     protected $twig;
  15.     /**
  16.      * @var FormFactoryInterface
  17.      */
  18.     protected $formFactory;
  19.     public function __construct(
  20.         Environment $twig,
  21.         FormFactoryInterface $formFactory
  22.     ) {
  23.         $this->twig $twig;
  24.         $this->formFactory $formFactory;
  25.     }
  26.     /**
  27.      * @param onKernelRequest $event
  28.      */
  29.     public function onKernelRequest(RequestEvent $event)
  30.     {
  31.         if (!$event->isMasterRequest()) {
  32.             return;
  33.         }
  34.         $route $event->getRequest()->attributes->get('_route');
  35.         if ($route !== 'mypage_history') {
  36.             log_info('[CJY:RequestEvent:checkout] Route@mypage_history ではない');
  37.             return;
  38.         }
  39.         $order_no $event->getRequest()->attributes->get('order_no');
  40.         $form $this->formFactory->create(UseOrderReturnType::class, ['order_no' => $order_no], ['order_no' => $order_no]);
  41.         
  42.         $form $form->createView();
  43.         $this->twig->addGlobal('use_or_form'$form);
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public static function getSubscribedEvents()
  49.     {
  50.         return [
  51.             KernelEvents::REQUEST => [
  52.                 ['onKernelRequest'10],
  53.             ]
  54.         ];
  55.     }
  56. }