-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29617: No route found after adding new translation (#256)
* EZP-29617: No route found after adding new translation * EZP-29617: No route found after adding new translation
- Loading branch information
Showing
3 changed files
with
127 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\RepositoryForms\Form\Processor; | ||
|
||
use eZ\Publish\API\Repository\LocationService; | ||
use eZ\Publish\API\Repository\URLAliasService; | ||
use EzSystems\RepositoryForms\Event\FormActionEvent; | ||
use EzSystems\RepositoryForms\Event\RepositoryFormEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class SystemUrlRedirectProcessor implements EventSubscriberInterface | ||
{ | ||
/** @var \Symfony\Component\Routing\RouterInterface */ | ||
private $router; | ||
|
||
/** @var \eZ\Publish\API\Repository\URLAliasService */ | ||
private $urlAliasService; | ||
|
||
/** @var \eZ\Publish\API\Repository\LocationService */ | ||
private $locationService; | ||
|
||
/** | ||
* @param \Symfony\Component\Routing\RouterInterface $router | ||
* @param \eZ\Publish\API\Repository\URLAliasService $urlAliasService | ||
* @param \eZ\Publish\API\Repository\LocationService $locationService | ||
* @param array $siteaccessGroups | ||
*/ | ||
public function __construct( | ||
RouterInterface $router, | ||
URLAliasService $urlAliasService, | ||
LocationService $locationService | ||
) { | ||
$this->router = $router; | ||
$this->urlAliasService = $urlAliasService; | ||
$this->locationService = $locationService; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
RepositoryFormEvents::CONTENT_PUBLISH => ['processRedirectAfterPublish', 2], | ||
RepositoryFormEvents::CONTENT_CANCEL => ['processRedirectAfterCancel', 2], | ||
]; | ||
} | ||
|
||
/** | ||
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
public function processRedirectAfterPublish(FormActionEvent $event): void | ||
{ | ||
if ($event->getForm()['redirectUrlAfterPublish']->getData()) { | ||
return; | ||
} | ||
|
||
$this->resolveSystemUrlRedirect($event); | ||
} | ||
|
||
/** | ||
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
public function processRedirectAfterCancel(FormActionEvent $event): void | ||
{ | ||
$this->resolveSystemUrlRedirect($event); | ||
} | ||
|
||
/** | ||
* @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; | ||
} | ||
|
||
$location = $this->locationService->loadLocation($params['locationId']); | ||
|
||
$event->setResponse(new RedirectResponse($this->urlAliasService->reverseLookup($location)->path)); | ||
} | ||
} |
Is this route not deprecated. Should we use ez_urlalias instead?