vendor/ibexa/form-builder/src/lib/Event/Subscriber/HandleSubmitAction.php line 80

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\FormBuilder\Event\Subscriber;
  8. use Ibexa\FormBuilder\Event\FormActionEvent;
  9. use Ibexa\FormBuilder\Event\FormEvents;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\Routing\RouterInterface;
  12. class HandleSubmitAction implements EventSubscriberInterface
  13. {
  14.     /** @var \Symfony\Component\Routing\RouterInterface */
  15.     protected $router;
  16.     /**
  17.      * @param \Symfony\Component\Routing\RouterInterface $router
  18.      */
  19.     public function __construct(
  20.         RouterInterface $router
  21.     ) {
  22.         $this->router $router;
  23.     }
  24.     /**
  25.      * Returns an array of event names this subscriber wants to listen to.
  26.      *
  27.      * The array keys are event names and the value can be:
  28.      *
  29.      *  * The method name to call (priority defaults to 0)
  30.      *  * An array composed of the method name to call and the priority
  31.      *  * An array of arrays composed of the method names to call and respective
  32.      *    priorities, or 0 if unset
  33.      *
  34.      * For instance:
  35.      *
  36.      *  * array('eventName' => 'methodName')
  37.      *  * array('eventName' => array('methodName', $priority))
  38.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  39.      *
  40.      * @return array The event names to listen to
  41.      */
  42.     public static function getSubscribedEvents()
  43.     {
  44.         return [
  45.             FormEvents::getSubmitActionEventName('url') => 'handleUrlRedirect',
  46.             FormEvents::getSubmitActionEventName('location_id') => 'handleLocationRedirect',
  47.             FormEvents::getSubmitActionEventName('message') => 'handleMessage',
  48.         ];
  49.     }
  50.     /**
  51.      * @param \Ibexa\FormBuilder\Event\FormActionEvent $event
  52.      *
  53.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
  54.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
  55.      * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
  56.      */
  57.     public function handleLocationRedirect(FormActionEvent $event)
  58.     {
  59.         $locationId $event->getData();
  60.         $contentView $event->getContentView();
  61.         $redirectUrl $this->router->generate('ibexa.url.alias', ['locationId' => $locationId]);
  62.         $contentView->addParameters(['redirect_url' => $redirectUrl]);
  63.         $contentView->setTemplateIdentifier('@ibexadesign/form_builder/form_submit_redirect.html.twig');
  64.     }
  65.     /**
  66.      * @param \Ibexa\FormBuilder\Event\FormActionEvent $event
  67.      *
  68.      * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
  69.      */
  70.     public function handleUrlRedirect(FormActionEvent $event)
  71.     {
  72.         $url $event->getData();
  73.         $contentView $event->getContentView();
  74.         $contentView->addParameters(['redirect_url' => $url]);
  75.         $contentView->setTemplateIdentifier('@ibexadesign/form_builder/form_submit_redirect.html.twig');
  76.     }
  77.     /**
  78.      * @param \Ibexa\FormBuilder\Event\FormActionEvent $event
  79.      *
  80.      * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
  81.      */
  82.     public function handleMessage(FormActionEvent $event)
  83.     {
  84.         $message $event->getData();
  85.         $contentView $event->getContentView();
  86.         $contentView->addParameters(['submit_message' => $message]);
  87.         $contentView->setTemplateIdentifier('@ibexadesign/form_builder/form_submit_message.html.twig');
  88.     }
  89. }
  90. class_alias(HandleSubmitAction::class, 'EzSystems\EzPlatformFormBuilder\Event\Subscriber\HandleSubmitAction');