Skip to content
Permalink
Browse files

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...
ViniTou authored and lserwatka committed Oct 11, 2018
1 parent b6cc9c8 commit 62160016078e2362e220a4eb6c858d683d49e267
@@ -208,7 +208,6 @@ services:
- '@ezpublish.api.service.content'
- '@ezpublish.api.service.location'
- '@router'
- '@ezpublish.api.service.url_alias'
tags:
- { name: kernel.event_subscriber }

@@ -251,6 +250,10 @@ services:
tags:
- { name: kernel.event_subscriber }

EzSystems\RepositoryForms\Form\Processor\SystemUrlRedirectProcessor:
autowire: true
autoconfigure: true

# Controllers
ezrepoforms.controller.content_edit:
class: "%ezrepoforms.controller.content_edit.class%"
@@ -9,7 +9,6 @@
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\URLAliasService;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\ContentStruct;
use eZ\Publish\API\Repository\Values\Content\Location;
@@ -21,6 +20,7 @@
use EzSystems\RepositoryForms\Event\RepositoryFormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
/**
@@ -37,9 +37,6 @@ class ContentFormProcessor implements EventSubscriberInterface
/** @var \Symfony\Component\Routing\RouterInterface */
private $router;
/** @var \eZ\Publish\API\Repository\URLAliasService */
private $urlAliasService;
/**
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\LocationService $locationService
@@ -49,13 +46,11 @@ class ContentFormProcessor implements EventSubscriberInterface
public function __construct(
ContentService $contentService,
LocationService $locationService,
RouterInterface $router,
URLAliasService $urlAliasService
RouterInterface $router
) {
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->router = $router;
$this->urlAliasService = $urlAliasService;
}
/**
@@ -110,7 +105,6 @@ public function processSaveDraft(FormActionEvent $event)
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
*/
@@ -123,35 +117,19 @@ public function processPublish(FormActionEvent $event)
$draft = $this->saveDraft($data, $form->getConfig()->getOption('languageCode'));
$content = $this->contentService->publishVersion($draft->versionInfo);
$location = $this->locationService->loadLocation($content->contentInfo->mainLocationId);
$redirectUrl = $form['redirectUrlAfterPublish']->getData() ?: $this->router->generate(
'_ezpublishLocation', [
'locationId' => $content->contentInfo->mainLocationId,
]
);
$redirectUrl = $form['redirectUrlAfterPublish']->getData() ?: $this->getSystemUrl($location, [$content->versionInfo->initialLanguageCode]);
$event->setResponse(new RedirectResponse($redirectUrl));
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
* @param array $prioritizedLanguageList
*
* @return string
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
private function getSystemUrl(Location $location, array $prioritizedLanguageList): string
{
return $this->urlAliasService->reverseLookup(
$location,
null,
true,
$prioritizedLanguageList
)->path;
}
/**
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function processCancel(FormActionEvent $event)
@@ -160,14 +138,10 @@ public function processCancel(FormActionEvent $event)
$data = $event->getData();
if ($data->isNew()) {
$parentLocation = $this->locationService->loadLocation(
$data->getLocationStructs()[0]->parentLocationId
);
$url = $this->getSystemUrl(
$parentLocation,
[$data->mainLanguageCode, $parentLocation->contentInfo->mainLanguageCode]
);
$response = new RedirectResponse($url);
$response = new RedirectResponse($this->router->generate(
'_ezpublishLocation',
['locationId' => $data->getLocationStructs()[0]->parentLocationId]
));
$event->setResponse($response);
return;
@@ -187,11 +161,10 @@ public function processCancel(FormActionEvent $event)
$this->contentService->deleteVersion($versionInfo);
}
$locationToRedirect = $this->locationService->loadLocation($redirectionLocationId);
$url = $this->getSystemUrl(
$locationToRedirect,
[$locationToRedirect->contentInfo->mainLanguageCode]
$url = $this->router->generate(
'_ezpublishLocation',
['locationId' => $redirectionLocationId],
UrlGeneratorInterface::ABSOLUTE_URL
);
$event->setResponse(new RedirectResponse($url));
@@ -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));
}
}

0 comments on commit 6216001

Please sign in to comment.
You can’t perform that action at this time.