vendor/ibexa/admin-ui/src/lib/Form/Processor/Content/UrlRedirectProcessor.php line 62

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\AdminUi\Form\Processor\Content;
  8. use Ibexa\AdminUi\Specification\SiteAccess\IsAdmin;
  9. use Ibexa\ContentForms\Event\ContentFormEvents;
  10. use Ibexa\ContentForms\Event\FormActionEvent;
  11. use Ibexa\ContentForms\Form\Processor\SystemUrlRedirectProcessor;
  12. use Ibexa\Core\MVC\Symfony\SiteAccess;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class UrlRedirectProcessor implements EventSubscriberInterface
  15. {
  16.     /** @var \Ibexa\Core\MVC\Symfony\SiteAccess */
  17.     private $siteaccess;
  18.     /** @var \Ibexa\ContentForms\Form\Processor\SystemUrlRedirectProcessor */
  19.     private $systemUrlRedirectProcessor;
  20.     /** @var array */
  21.     private $siteaccessGroups;
  22.     /**
  23.      * @param \Ibexa\Core\MVC\Symfony\SiteAccess $siteaccess
  24.      * @param \Ibexa\ContentForms\Form\Processor\SystemUrlRedirectProcessor $systemUrlRedirectProcessor
  25.      * @param array $siteaccessGroups
  26.      */
  27.     public function __construct(
  28.         SiteAccess $siteaccess,
  29.         SystemUrlRedirectProcessor $systemUrlRedirectProcessor,
  30.         array $siteaccessGroups
  31.     ) {
  32.         $this->siteaccess $siteaccess;
  33.         $this->systemUrlRedirectProcessor $systemUrlRedirectProcessor;
  34.         $this->siteaccessGroups $siteaccessGroups;
  35.     }
  36.     /**
  37.      * @return array
  38.      */
  39.     public static function getSubscribedEvents(): array
  40.     {
  41.         return [
  42.             ContentFormEvents::CONTENT_PUBLISH => ['processRedirectAfterPublish'0],
  43.             ContentFormEvents::CONTENT_CANCEL => ['processRedirectAfterCancel'0],
  44.         ];
  45.     }
  46.     /**
  47.      * @param \Ibexa\ContentForms\Event\FormActionEvent $event
  48.      *
  49.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  50.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
  51.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
  52.      */
  53.     public function processRedirectAfterPublish(FormActionEvent $event): void
  54.     {
  55.         if ($event->getForm()['redirectUrlAfterPublish']->getData()) {
  56.             return;
  57.         }
  58.         if ($this->isAdminSiteaccess()) {
  59.             return;
  60.         }
  61.         $this->systemUrlRedirectProcessor->processRedirectAfterPublish($event);
  62.     }
  63.     /**
  64.      * @param \Ibexa\ContentForms\Event\FormActionEvent $event
  65.      *
  66.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  67.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
  68.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
  69.      */
  70.     public function processRedirectAfterCancel(FormActionEvent $event): void
  71.     {
  72.         if ($this->isAdminSiteaccess()) {
  73.             return;
  74.         }
  75.         $this->systemUrlRedirectProcessor->processRedirectAfterCancel($event);
  76.     }
  77.     /**
  78.      * @return bool
  79.      *
  80.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  81.      */
  82.     protected function isAdminSiteaccess(): bool
  83.     {
  84.         return (new IsAdmin($this->siteaccessGroups))->isSatisfiedBy($this->siteaccess);
  85.     }
  86. }
  87. class_alias(UrlRedirectProcessor::class, 'EzSystems\EzPlatformAdminUi\Form\Processor\Content\UrlRedirectProcessor');