Skip to content

Commit

Permalink
EZP-31310: Fixed editing for content with multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
lserwatka authored and mikadamczyk committed Feb 19, 2020
2 parents 0a984ee + 3a5d55c commit 0356db8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib/Content/View/Builder/ContentEditViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace EzSystems\EzPlatformContentForms\Content\View\Builder;

use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Language;
Expand Down Expand Up @@ -105,8 +106,14 @@ public function buildView(array $parameters)
}

if (null === $location && $isPublished) {
// assume main location if no location was provided
$location = $this->loadLocation((int) $contentInfo->mainLocationId);
try {
// assume main location if no location was provided
$location = $this->loadLocation((int) $contentInfo->mainLocationId);
} catch (UnauthorizedException $e) {
// if no access to the main location assume content has multiple locations and first of them can be used
$availableLocations = $this->repository->getLocationService()->loadLocations($contentInfo);
$location = array_shift($availableLocations);
}
}

if (null !== $location && $location->contentId !== $content->id) {
Expand Down Expand Up @@ -275,7 +282,11 @@ private function resolveContent(array $parameters, ?Location $location, Language
private function resolveLocation(array $parameters): ?Location
{
if (isset($parameters['locationId'])) {
return $this->loadLocation((int) $parameters['locationId']);
try {
// the load error is suppressed because a user can have no permission to this location
// but can have access to another location when content is in multiple locations
return $this->loadLocation((int) $parameters['locationId']);
} catch (UnauthorizedException $e) {}
}

if (isset($parameters['location'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testMapFieldValueFormNoLanguageCode()
$fieldDefinition = new FieldDefinition([
'names' => [],
'isRequired' => false,
'fieldTypeIdentifier' => 'ezselection',
'fieldSettings' => ['isMultiple' => false, 'options' => []],
]);

Expand All @@ -45,6 +46,7 @@ public function testMapFieldValueFormWithLanguageCode()
$fieldDefinition = new FieldDefinition([
'names' => ['eng-GB' => 'foo'],
'isRequired' => false,
'fieldTypeIdentifier' => 'ezselection',
'fieldSettings' => ['isMultiple' => false, 'options' => []],
]);
$this->data->expects($this->once())
Expand Down

0 comments on commit 0356db8

Please sign in to comment.