From 029227556470a5a542e5878c35906796147b4ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Serwatka?= Date: Wed, 16 Sep 2020 10:47:48 +0200 Subject: [PATCH] Revert "EZP-31086: Redirect based on router, not url alias (#1122)" (#1487) This reverts commit 7518ff4aa22e0485946b6550b3bbad40fa32e74b. --- .../config/services/form_processors.yml | 5 +- ...Processor.php => UrlRedirectProcessor.php} | 54 +++++-------------- 2 files changed, 15 insertions(+), 44 deletions(-) rename src/lib/RepositoryForms/Form/Processor/Content/{SystemUrlRedirectProcessor.php => UrlRedirectProcessor.php} (64%) diff --git a/src/bundle/Resources/config/services/form_processors.yml b/src/bundle/Resources/config/services/form_processors.yml index 3122a348ad..326196f065 100644 --- a/src/bundle/Resources/config/services/form_processors.yml +++ b/src/bundle/Resources/config/services/form_processors.yml @@ -17,8 +17,9 @@ services: arguments: $siteAccessGroups: '%ezpublish.siteaccess.groups%' - EzSystems\EzPlatformAdminUi\RepositoryForms\Form\Processor\Content\SystemUrlRedirectProcessor: + EzSystems\EzPlatformAdminUi\RepositoryForms\Form\Processor\Content\UrlRedirectProcessor: public: true + decorates: EzSystems\RepositoryForms\Form\Processor\SystemUrlRedirectProcessor arguments: $siteaccessGroups: '%ezpublish.siteaccess.groups%' - + $systemUrlRedirectProcessor: '@EzSystems\EzPlatformAdminUi\RepositoryForms\Form\Processor\Content\UrlRedirectProcessor.inner' diff --git a/src/lib/RepositoryForms/Form/Processor/Content/SystemUrlRedirectProcessor.php b/src/lib/RepositoryForms/Form/Processor/Content/UrlRedirectProcessor.php similarity index 64% rename from src/lib/RepositoryForms/Form/Processor/Content/SystemUrlRedirectProcessor.php rename to src/lib/RepositoryForms/Form/Processor/Content/UrlRedirectProcessor.php index f4c3c10aef..14470ef4fc 100644 --- a/src/lib/RepositoryForms/Form/Processor/Content/SystemUrlRedirectProcessor.php +++ b/src/lib/RepositoryForms/Form/Processor/Content/UrlRedirectProcessor.php @@ -12,33 +12,32 @@ use EzSystems\EzPlatformAdminUi\Specification\SiteAccess\IsAdmin; use EzSystems\RepositoryForms\Event\FormActionEvent; use EzSystems\RepositoryForms\Event\RepositoryFormEvents; +use EzSystems\RepositoryForms\Form\Processor\SystemUrlRedirectProcessor; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\Routing\RouterInterface; -class SystemUrlRedirectProcessor implements EventSubscriberInterface +class UrlRedirectProcessor implements EventSubscriberInterface { /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess */ private $siteaccess; - /** @var \Symfony\Component\Routing\RouterInterface */ - private $router; + /** @var \EzSystems\RepositoryForms\Form\Processor\SystemUrlRedirectProcessor */ + private $systemUrlRedirectProcessor; /** @var array */ private $siteaccessGroups; /** * @param \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteaccess - * @param \Symfony\Component\Routing\RouterInterface $router + * @param \EzSystems\RepositoryForms\Form\Processor\SystemUrlRedirectProcessor $systemUrlRedirectProcessor * @param array $siteaccessGroups */ public function __construct( SiteAccess $siteaccess, - RouterInterface $router, + SystemUrlRedirectProcessor $systemUrlRedirectProcessor, array $siteaccessGroups ) { $this->siteaccess = $siteaccess; - $this->router = $router; + $this->systemUrlRedirectProcessor = $systemUrlRedirectProcessor; $this->siteaccessGroups = $siteaccessGroups; } @@ -66,11 +65,11 @@ public function processRedirectAfterPublish(FormActionEvent $event): void return; } - if (!$this->isAdminSiteaccess()) { + if ($this->isAdminSiteaccess()) { return; } - $this->resolveSystemUrlRedirect($event); + $this->systemUrlRedirectProcessor->processRedirectAfterPublish($event); } /** @@ -82,11 +81,11 @@ public function processRedirectAfterPublish(FormActionEvent $event): void */ public function processRedirectAfterCancel(FormActionEvent $event): void { - if (!$this->isAdminSiteaccess()) { + if ($this->isAdminSiteaccess()) { return; } - - $this->resolveSystemUrlRedirect($event); + + $this->systemUrlRedirectProcessor->processRedirectAfterCancel($event); } /** @@ -98,33 +97,4 @@ protected function isAdminSiteaccess(): bool { return (new IsAdmin($this->siteaccessGroups))->isSatisfiedBy($this->siteaccess); } - - /** - * @param \EzSystems\RepositoryForms\Event\FormActionEvent $event - * - * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - */ - private function resolveSystemUrlRedirect(FormActionEvent $event): void - { - /** @var \Symfony\Component\HttpFoundation\RedirectResponse $response */ - $response = $event->getResponse(); - - if (!$response instanceof RedirectResponse) { - return; - } - - $params = $this->router->match($response->getTargetUrl()); - - if (!in_array('locationId', $params)) { - return; - } - - $url = $this->router->generate( - '_ezpublishLocation', ['locationId' => $params['locationId']] - ); - - $event->setResponse(new RedirectResponse($url)); - } } -