Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch '1.3' of ezsystems/ezplatform-kernel into 4.5 #289

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/bundle/Core/Converter/LocationParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
namespace Ibexa\Bundle\Core\Converter;

use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Core\Helper\ContentPreviewHelper;

class LocationParamConverter extends RepositoryParamConverter
{
/** @var \Ibexa\Contracts\Core\Repository\LocationService */
private $locationService;

public function __construct(LocationService $locationService)
{
private ContentPreviewHelper $contentPreviewHelper;

public function __construct(
LocationService $locationService,
ContentPreviewHelper $contentPreviewHelper
) {
$this->locationService = $locationService;
$this->contentPreviewHelper = $contentPreviewHelper;
}

protected function getSupportedClass()
Expand All @@ -29,9 +36,15 @@ protected function getPropertyName()
return 'locationId';
}

protected function loadValueObject($id)
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
protected function loadValueObject($id): Location
{
return $this->locationService->loadLocation($id);
$prioritizedLanguages = $this->contentPreviewHelper->isPreviewActive() ? Language::ALL : null;

return $this->locationService->loadLocation($id, $prioritizedLanguages);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/bundle/Core/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ services:
Ibexa\Bundle\Core\Converter\LocationParamConverter:
class: Ibexa\Bundle\Core\Converter\LocationParamConverter
arguments:
- '@ibexa.siteaccessaware.service.location'
$locationService: '@ibexa.siteaccessaware.service.location'
$contentPreviewHelper: '@Ibexa\Core\Helper\ContentPreviewHelper'
tags:
- { name: request.param_converter, priority: '%ibexa.param_converter.location.priority%', converter: ez_location_converter }

Expand Down
17 changes: 15 additions & 2 deletions src/lib/MVC/Symfony/Templating/Twig/Extension/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension;

use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
Expand Down Expand Up @@ -103,14 +104,26 @@ public function getPath(object $name, array $parameters = [], bool $relative = f
{
$referenceType = $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH;

return $this->generateUrlForObject($name, $parameters, $referenceType);
return $this->tryGeneratingUrlForObject($name, $parameters, $referenceType);
}

public function getUrl(object $name, array $parameters = [], bool $schemeRelative = false): string
{
$referenceType = $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL;

return $this->generateUrlForObject($name, $parameters, $referenceType);
return $this->tryGeneratingUrlForObject($name, $parameters, $referenceType);
}

/**
* @param array<string, mixed> $parameters
*/
private function tryGeneratingUrlForObject(object $object, array $parameters, int $referenceType): string
{
try {
return $this->generateUrlForObject($object, $parameters, $referenceType);
} catch (NotFoundException $e) {
return '';
}
}

private function generateUrlForObject(object $object, array $parameters, int $referenceType): string
Expand Down
4 changes: 3 additions & 1 deletion tests/bundle/Core/Converter/LocationParamConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Ibexa\Bundle\Core\Converter\LocationParamConverter;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Core\Helper\ContentPreviewHelper;
use Symfony\Component\HttpFoundation\Request;

class LocationParamConverterTest extends AbstractParamConverterTest
Expand All @@ -25,8 +26,9 @@ class LocationParamConverterTest extends AbstractParamConverterTest
protected function setUp(): void
{
$this->locationServiceMock = $this->createMock(LocationService::class);
$contentPreviewHelper = $this->createMock(ContentPreviewHelper::class);

$this->converter = new LocationParamConverter($this->locationServiceMock);
$this->converter = new LocationParamConverter($this->locationServiceMock, $contentPreviewHelper);
}

public function testSupports()
Expand Down
Loading