Skip to content

Commit

Permalink
Merge pull request #98 from ezsystems/ibx-1972-refactored-location-he…
Browse files Browse the repository at this point in the history
…lper

IBX-1972: Refactored LocationHelper::getParentLocationPathString
  • Loading branch information
ciastektk authored Jan 18, 2022
2 parents 164c122 + 246fd5a commit b7ccb43
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib/Helper/LocationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,18 @@ public function areLocationsVisible(ContentInfo $contentInfo): bool
/**
* Returns location path string based on $contentId.
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function getParentLocationPathString(int $contentId): ?string
{
$content = $this->contentService->loadContent($contentId);
$mainLocationId = $content->contentInfo->mainLocationId;
if (null === $mainLocationId) {
return null;
}

try {
$location = $this->locationService->loadLocation($mainLocationId);
$parentLocation = $location->getParentLocation();
$content = $this->contentService->loadContent($contentId);
$mainLocation = $content->contentInfo->getMainLocation();
if (null === $mainLocation) {
return null;
}

$parentLocation = $mainLocation->getParentLocation();

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

0 comments on commit b7ccb43

Please sign in to comment.