Skip to content

Commit 21adc1b

Browse files
petarjakopecpspanja
authored andcommitted
NGSTACK-816 remove redundant checks in UrlsTab
1 parent 8609983 commit 21adc1b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

bundle/Tab/LocationView/UrlsTab.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Contracts\Translation\TranslatorInterface;
1616
use Twig\Environment;
1717

18-
use function array_search;
18+
use function in_array;
1919
use function preg_match;
2020

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

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

82-
$locationIdIndex = array_search((string) $location->id, $locationPath, true);
83-
$rootLocationId = $this->configResolver->getParameter(
84-
'content.tree_root.location_id',
85-
null,
86-
$siteaccess,
87-
);
88-
$rootLocationIdIndex = array_search((string) $rootLocationId, $locationPath, true);
89-
90-
// checks if the url is inside configured siteaccess content tree
91-
if ($locationIdIndex !== false && $rootLocationIdIndex !== false && $rootLocationIdIndex <= $locationIdIndex) {
81+
if ($this->isUnderConfiguredContentTreeRoot($location, $siteaccess)) {
9282
$siteaccessUrls[$siteaccess] = $url;
9383
} else {
9484
$siteaccessUrlsOutsideConfiguredContentTreeRoot[$siteaccess] = $url;
@@ -105,4 +95,15 @@ public function getTemplateParameters(array $contextParameters = []): array
10595

10696
return $parentParameters + $parameters;
10797
}
98+
99+
private function isUnderConfiguredContentTreeRoot(Location $location, string $siteaccess): bool
100+
{
101+
$rootLocationId = $this->configResolver->getParameter(
102+
'content.tree_root.location_id',
103+
null,
104+
$siteaccess,
105+
);
106+
107+
return in_array((string) $rootLocationId, $location->path, true);
108+
}
108109
}

0 commit comments

Comments
 (0)