Skip to content

Commit

Permalink
IBX-199: Fixed multi-category paths (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk authored Nov 19, 2021
1 parent c7334eb commit 7963fe8
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/lib/Service/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand All @@ -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<string>
*
* @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
Expand Down

0 comments on commit 7963fe8

Please sign in to comment.