Skip to content

Commit

Permalink
Fixed getParentLocationPathString in LocationHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jan 18, 2022
1 parent 5fe4df5 commit 4493467
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,6 @@ parameters:
count: 1
path: src/lib/Helper/ImageHelper.php

-
message: "#^Parameter \\#1 \\$locationId of method eZ\\\\Publish\\\\API\\\\Repository\\\\LocationService\\:\\:loadLocation\\(\\) expects int, int\\|null given\\.$#"
count: 1
path: src/lib/Helper/LocationHelper.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Helper\\\\ParamsConverterHelper\\:\\:getArrayFromString\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
18 changes: 14 additions & 4 deletions src/lib/Helper/LocationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace EzSystems\EzRecommendationClient\Helper;

use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;

Expand Down Expand Up @@ -50,12 +51,21 @@ public function areLocationsVisible(ContentInfo $contentInfo): bool
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function getParentLocationPathString(int $contentId): string
public function getParentLocationPathString(int $contentId): ?string
{
$content = $this->contentService->loadContent($contentId);
$location = $this->locationService->loadLocation($content->contentInfo->mainLocationId);
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
$mainLocationId = $content->contentInfo->mainLocationId;
if (null === $mainLocationId) {
return null;
}

try {
$location = $this->locationService->loadLocation($mainLocationId);
$parentLocation = $location->getParentLocation();

return $parentLocation->pathString;
return null !== $parentLocation ? $parentLocation->pathString : null;
} catch (NotFoundException $exception) {
return null;
}
}
}

0 comments on commit 4493467

Please sign in to comment.