Skip to content

Commit

Permalink
NGSTACK-816 remove redundant checks in UrlsTab
Browse files Browse the repository at this point in the history
  • Loading branch information
petarjakopec committed Aug 27, 2024
1 parent 2bda698 commit 122f36a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions bundle/Tab/LocationView/UrlsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

use function array_search;
use function in_array;
use function preg_match;

final class UrlsTab extends AbstractEventDispatchingTab implements OrderedTabInterface
Expand Down Expand Up @@ -63,7 +63,6 @@ public function getTemplateParameters(array $contextParameters = []): array
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
$location = $contextParameters['location'];

$locationPath = $location->path;
foreach ($this->siteaccessList as $siteaccess) {
$url = $this->router->generate(
'ibexa.url.alias',
Expand All @@ -79,16 +78,7 @@ public function getTemplateParameters(array $contextParameters = []): array
continue;
}

$locationIdIndex = array_search((string) $location->id, $locationPath, true);
$rootLocationId = $this->configResolver->getParameter(
'content.tree_root.location_id',
null,
$siteaccess,
);
$rootLocationIdIndex = array_search((string) $rootLocationId, $locationPath, true);

// checks if the url is inside configured siteaccess content tree
if ($locationIdIndex !== false && $rootLocationIdIndex !== false && $rootLocationIdIndex <= $locationIdIndex) {
if ($this->isUnderConfiguredContentTreeRoot($location, $siteaccess)) {
$siteaccessUrls[$siteaccess] = $url;
} else {
$siteaccessUrlsOutsideConfiguredContentTreeRoot[$siteaccess] = $url;
Expand All @@ -105,4 +95,15 @@ public function getTemplateParameters(array $contextParameters = []): array

return $parentParameters + $parameters;
}

private function isUnderConfiguredContentTreeRoot(Location $location, string $siteaccess): bool
{
$rootLocationId = $this->configResolver->getParameter(
'content.tree_root.location_id',
null,
$siteaccess,
);

return in_array((string) $rootLocationId, $location->path, true);
}
}

0 comments on commit 122f36a

Please sign in to comment.