diff --git a/app/Views/admin/layout.php b/app/Views/admin/layout.php index ecc4d1e..3494f30 100644 --- a/app/Views/admin/layout.php +++ b/app/Views/admin/layout.php @@ -16,17 +16,21 @@ $userNav = session_user_nav_display(); $currentPath = current_nav_request_path(); $adminNavTree = get_admin_nav_tree(); +$resolveAdminNavNodeMatchLen = static function (object $node) use ($currentPath): int { + $maxLen = -1; + foreach (menu_link_candidate_paths($node->mm_link ?? null, $currentPath) as $cand) { + if (menu_single_path_matches_request($cand, $currentPath, [])) { + $maxLen = max($maxLen, strlen($cand)); + } + } + return $maxLen; +}; + $activeAdminTopNav = null; $activeAdminTopLen = -1; $activeAdminTopNum = PHP_INT_MAX; foreach ($adminNavTree as $topNode) { - $nodeLen = -1; - $activeChild = site_nav_active_child_for_parent($topNode, $currentPath, []); - if ($activeChild !== null) { - $nodeLen = strlen(menu_link_preferred_href_path($activeChild->mm_link ?? null, $currentPath)); - } elseif (menu_link_matches_request($topNode->mm_link ?? null, $currentPath, [])) { - $nodeLen = strlen(menu_link_preferred_href_path($topNode->mm_link ?? null, $currentPath)); - } + $nodeLen = $resolveAdminNavNodeMatchLen($topNode); if ($nodeLen > $activeAdminTopLen || ($nodeLen === $activeAdminTopLen && (int) ($topNode->mm_num ?? 0) < $activeAdminTopNum)) { $activeAdminTopNav = $topNode; $activeAdminTopLen = $nodeLen; diff --git a/app/Views/bag/layout/main.php b/app/Views/bag/layout/main.php index cafe28b..76de08c 100644 --- a/app/Views/bag/layout/main.php +++ b/app/Views/bag/layout/main.php @@ -14,17 +14,21 @@ if ($effectiveLgIdx) { } $userNav = session_user_nav_display(); +$resolveNavNodeMatchLen = static function (object $node) use ($currentPath, $dashboardPathAliases): int { + $maxLen = -1; + foreach (menu_link_candidate_paths($node->mm_link ?? null, $currentPath) as $cand) { + if (menu_single_path_matches_request($cand, $currentPath, $dashboardPathAliases)) { + $maxLen = max($maxLen, strlen($cand)); + } + } + return $maxLen; +}; + $activeTopNav = null; $activeTopLen = -1; $activeTopNum = PHP_INT_MAX; foreach ($siteNavTree as $topNode) { - $nodeLen = -1; - $activeChild = site_nav_active_child_for_parent($topNode, $currentPath, $dashboardPathAliases); - if ($activeChild !== null) { - $nodeLen = strlen(menu_link_preferred_href_path($activeChild->mm_link ?? null, $currentPath)); - } elseif (site_nav_link_matches_current($topNode->mm_link ?? null, $currentPath, $dashboardPathAliases)) { - $nodeLen = strlen(menu_link_preferred_href_path($topNode->mm_link ?? null, $currentPath)); - } + $nodeLen = $resolveNavNodeMatchLen($topNode); if ($nodeLen > $activeTopLen || ($nodeLen === $activeTopLen && (int) ($topNode->mm_num ?? 0) < $activeTopNum)) { $activeTop = $topNode; $activeTopLen = $nodeLen;