Skip to content

Commit

Permalink
Revert "EZP-31086: Redirect based on router, not url alias (#1122)" (#…
Browse files Browse the repository at this point in the history
…1487)

This reverts commit 7518ff4.
  • Loading branch information
lserwatka authored Sep 16, 2020
1 parent 7518ff4 commit 0292275
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
5 changes: 3 additions & 2 deletions src/bundle/Resources/config/services/form_processors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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));
}
}

0 comments on commit 0292275

Please sign in to comment.