diff --git a/src/lib/Service/ContentService.php b/src/lib/Service/ContentService.php index 2360bff6..f08b1bc5 100644 --- a/src/lib/Service/ContentService.php +++ b/src/lib/Service/ContentService.php @@ -13,6 +13,7 @@ use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; use eZ\Publish\API\Repository\LocationService as LocationServiceInterface; use eZ\Publish\API\Repository\Values\Content\Content as APIContent; +use eZ\Publish\API\Repository\Values\Content\ContentInfo; use eZ\Publish\API\Repository\Values\ContentType\ContentType as APIContentType; use eZ\Publish\Core\Repository\Values\Content\Content as CoreContent; use EzSystems\EzRecommendationClient\Field\Value; @@ -149,12 +150,14 @@ public function prepareContent(array $data, ContentOptions $options, ?OutputInte * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException */ public function setContent(CoreContent $content, ContentOptions $options): array { - $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); + $contentInfo = $content->contentInfo; + $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId); $this->value->setFieldDefinitionsList($contentType); - $location = $this->locationService->loadLocation($content->contentInfo->mainLocationId); + $location = $this->locationService->loadLocation($contentInfo->mainLocationId); $language = $options->lang ?? $location->contentInfo->mainLanguageCode; $uriParams = [ @@ -176,11 +179,28 @@ public function setContent(CoreContent $content, ContentOptions $options): array 'locations' => [ 'href' => '/api/ezp/v2/content/objects/' . $content->id . '/locations', ], - 'categoryPath' => $location->pathString, + 'categoryPath' => $this->getCategoryPaths($contentInfo), 'fields' => $this->setFields($content, $contentType, $options, $language), ]; } + /** + * @return array + * + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + */ + private function getCategoryPaths(ContentInfo $contentInfo): array + { + $categoryPaths = []; + $locations = $this->locationService->loadLocations($contentInfo); + + foreach ($locations as $location) { + $categoryPaths[] = $location->pathString; + } + + return $categoryPaths; + } + /** * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException