diff --git a/src/lib/Content/View/Builder/ContentEditViewBuilder.php b/src/lib/Content/View/Builder/ContentEditViewBuilder.php index d529fa94..5b1c6974 100644 --- a/src/lib/Content/View/Builder/ContentEditViewBuilder.php +++ b/src/lib/Content/View/Builder/ContentEditViewBuilder.php @@ -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; @@ -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) { @@ -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'])) { diff --git a/src/lib/Tests/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php b/src/lib/Tests/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php index f394270b..f16ca67e 100644 --- a/src/lib/Tests/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php +++ b/src/lib/Tests/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php @@ -20,6 +20,7 @@ public function testMapFieldValueFormNoLanguageCode() $fieldDefinition = new FieldDefinition([ 'names' => [], 'isRequired' => false, + 'fieldTypeIdentifier' => 'ezselection', 'fieldSettings' => ['isMultiple' => false, 'options' => []], ]); @@ -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())