vendor/ezsystems/repository-forms/lib/Form/Processor/User/UserCancelFormProcessor.php line 44

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the eZ RepositoryForms package.
  4.  *
  5.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  6.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  7.  *
  8.  * @version //autogentag//
  9.  */
  10. namespace EzSystems\RepositoryForms\Form\Processor\User;
  11. use EzSystems\RepositoryForms\Data\User\UserCreateData;
  12. use EzSystems\RepositoryForms\Data\User\UserUpdateData;
  13. use EzSystems\RepositoryForms\Event\FormActionEvent;
  14. use EzSystems\RepositoryForms\Event\RepositoryFormEvents;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpFoundation\RedirectResponse;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. /**
  19.  * Listens for and processes User cancel events.
  20.  */
  21. class UserCancelFormProcessor implements EventSubscriberInterface
  22. {
  23.     /** @var UrlGeneratorInterface */
  24.     private $urlGenerator;
  25.     /**
  26.      * @param UrlGeneratorInterface $urlGenerator
  27.      */
  28.     public function __construct(
  29.         UrlGeneratorInterface $urlGenerator
  30.     ) {
  31.         $this->urlGenerator $urlGenerator;
  32.     }
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             RepositoryFormEvents::USER_CANCEL => ['processCancel'10],
  37.         ];
  38.     }
  39.     public function processCancel(FormActionEvent $event)
  40.     {
  41.         /** @var UserUpdateData|UserCreateData $data */
  42.         $data $event->getData();
  43.         $locationId $data->isNew()
  44.             ? $data->getParentGroups()[0]->contentInfo->mainLocationId
  45.             $data->user->contentInfo->mainLocationId;
  46.         $response = new RedirectResponse($this->urlGenerator->generate('_ezpublishLocation', [
  47.             'locationId' => $locationId,
  48.         ]));
  49.         $event->setResponse($response);
  50.     }
  51. }