From 21adc1b651969a2140ef5b0bfac33d5d2bd61932 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 11:08:32 +0200 Subject: [PATCH] NGSTACK-816 remove redundant checks in UrlsTab --- bundle/Tab/LocationView/UrlsTab.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php index 819ec6a..c71c962 100644 --- a/bundle/Tab/LocationView/UrlsTab.php +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -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 @@ -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', @@ -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; @@ -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); + } }