Skip to content

Commit

Permalink
IBX-6504: Load all locations when preview is active in `LocationParam…
Browse files Browse the repository at this point in the history
…Converter`
  • Loading branch information
barw4 committed Oct 24, 2023
1 parent 791b764 commit 124723a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
19 changes: 16 additions & 3 deletions eZ/Bundle/EzPublishCoreBundle/Converter/LocationParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
namespace eZ\Bundle\EzPublishCoreBundle\Converter;

use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\Helper\ContentPreviewHelper;

class LocationParamConverter extends RepositoryParamConverter
{
/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;

public function __construct(LocationService $locationService)
/** @var \eZ\Publish\Core\Helper\ContentPreviewHelper */
private $contentPreviewHelper;

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

protected function getSupportedClass()
Expand All @@ -28,8 +35,14 @@ protected function getPropertyName()
return 'locationId';
}

protected function loadValueObject($id)
/**
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\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);
}
}
3 changes: 2 additions & 1 deletion eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ services:
ezpublish.param_converter.location:
class: eZ\Bundle\EzPublishCoreBundle\Converter\LocationParamConverter
arguments:
- "@ezpublish.siteaccessaware.service.location"
$locationService: "@ezpublish.siteaccessaware.service.location"
$contentPreviewHelper: '@ezpublish.content_preview_helper'
tags:
- { name: request.param_converter, priority: "%ezpublish.param_converter.location.priority%", converter: ez_location_converter }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use eZ\Bundle\EzPublishCoreBundle\Converter\LocationParamConverter;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\Helper\ContentPreviewHelper;
use Symfony\Component\HttpFoundation\Request;

class LocationParamConverterTest extends AbstractParamConverterTest
Expand All @@ -22,11 +23,15 @@ class LocationParamConverterTest extends AbstractParamConverterTest

private $locationServiceMock;

/** @var \eZ\Publish\Core\Helper\ContentPreviewHelper&\PHPUnit\Framework\MockObject\MockObject */
private $contentPreviewHelperMock;

protected function setUp(): void
{
$this->locationServiceMock = $this->createMock(LocationService::class);
$this->contentPreviewHelperMock = $this->createMock(ContentPreviewHelper::class);

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

public function testSupports()
Expand Down

0 comments on commit 124723a

Please sign in to comment.