Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-199: Fixed multi-category paths #92

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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