Skip to content

Commit

Permalink
IBX-6504: Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 19, 2023
1 parent 87489f2 commit 05d8a8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion eZ/Publish/Core/MVC/Symfony/Routing/UrlAliasRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function generate(string $name, array $parameters = [], int $referenceTyp

$location = $parameters['location'] ?? $this->locationService->loadLocation(
$parameters['locationId'],
isset($parameters['forcedLanguage']) ? [$parameters['forcedLanguage']] : null
isset($parameters['forcedLanguageCode']) ? [$parameters['forcedLanguageCode']] : null
);
unset($parameters['location'], $parameters['locationId'], $parameters['viewType'], $parameters['layout']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

namespace eZ\Publish\Core\MVC\Symfony\Templating\Tests\Twig\Extension;

use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\Values\Content\Content as APIContent;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location as APILocation;
use eZ\Publish\Core\Helper\ContentPreviewHelper;
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator;
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGeneratorInterface;
use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference;
Expand All @@ -32,7 +34,9 @@ protected function getExtensions(): array
return [
new RoutingExtension(
$this->getRouteReferenceGenerator(),
$this->getUrlGenerator()
$this->getUrlGenerator(),
$this->createMock(ContentPreviewHelper::class),
$this->createMock(LocationService::class),
),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,25 @@ private function generateUrlForObject(object $object, array $parameters, int $re
{
if ($object instanceof Location) {
$routeName = UrlAliasRouter::URL_ALIAS_ROUTE_NAME;
$forcedLanguageCode = $this->getForcedLanguageCodeBasedOnPreview();
if ($forcedLanguageCode !== null) {
$parameters += [
'forcedLanguageCode' => $forcedLanguageCode,
];
}
$parameters += [
'locationId' => $object->id,
'forcedLanguage' => $this->getForcedLanguageCodeBasedOnPreview(),
];
} elseif ($object instanceof Content || $object instanceof ContentInfo) {
$routeName = UrlAliasRouter::URL_ALIAS_ROUTE_NAME;
$forcedLanguageCode = $this->getForcedLanguageCodeBasedOnPreview();
if ($forcedLanguageCode !== null) {
$parameters += [
'forcedLanguageCode' => $forcedLanguageCode,
];
}
$parameters += [
'contentId' => $object->id,
'forcedLanguage' => $this->getForcedLanguageCodeBasedOnPreview(),
];
} elseif ($object instanceof RouteReference) {
$routeName = $object->getRoute();
Expand All @@ -142,7 +152,7 @@ private function generateUrlForObject(object $object, array $parameters, int $re
*/
private function getForcedLanguageCodeBasedOnPreview(): ?string
{
if ($this->contentPreviewHelper->isPreviewActive() === false) {
if ($this->contentPreviewHelper->isPreviewActive() !== true) {
return null;
}

Expand Down

0 comments on commit 05d8a8e

Please sign in to comment.