vendor/ibexa/content-forms/src/lib/Form/Processor/User/UserCancelFormProcessor.php line 41

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\ContentForms\Form\Processor\User;
  8. use Ibexa\ContentForms\Event\ContentFormEvents;
  9. use Ibexa\ContentForms\Event\FormActionEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  13. /**
  14.  * Listens for and processes User cancel events.
  15.  */
  16. class UserCancelFormProcessor implements EventSubscriberInterface
  17. {
  18.     /** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
  19.     private $urlGenerator;
  20.     /**
  21.      * @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator
  22.      */
  23.     public function __construct(
  24.         UrlGeneratorInterface $urlGenerator
  25.     ) {
  26.         $this->urlGenerator $urlGenerator;
  27.     }
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             ContentFormEvents::USER_CANCEL => ['processCancel'10],
  32.         ];
  33.     }
  34.     public function processCancel(FormActionEvent $event)
  35.     {
  36.         /** @var \Ibexa\ContentForms\Data\User\UserUpdateData|\Ibexa\ContentForms\Data\User\UserCreateData $data */
  37.         $data $event->getData();
  38.         $contentInfo $data->isNew()
  39.             ? $data->getParentGroups()[0]->contentInfo
  40.             $data->user->contentInfo;
  41.         $response = new RedirectResponse($this->urlGenerator->generate('ibexa.content.view', [
  42.             'contentId' => $contentInfo->id,
  43.             'locationId' => $contentInfo->mainLocationId,
  44.         ]));
  45.         $event->setResponse($response);
  46.     }
  47. }
  48. class_alias(UserCancelFormProcessor::class, 'EzSystems\EzPlatformContentForms\Form\Processor\User\UserCancelFormProcessor');