diff --git a/app/Views/admin/layout.php b/app/Views/admin/layout.php index 3494f30..1fc8265 100644 --- a/app/Views/admin/layout.php +++ b/app/Views/admin/layout.php @@ -16,28 +16,11 @@ $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; +/** DB 링크(mm_link)만 사용. 짧게 적은 항목(menus 등)은 실제 URI(admin/menus)와 맞춰 후보 비교 */ +$adminNavItemIsCurrent = static function (?string $mmLink) use ($currentPath): bool { + return menu_link_matches_request($mmLink, $currentPath, []); }; -$activeAdminTopNav = null; -$activeAdminTopLen = -1; -$activeAdminTopNum = PHP_INT_MAX; -foreach ($adminNavTree as $topNode) { - $nodeLen = $resolveAdminNavNodeMatchLen($topNode); - if ($nodeLen > $activeAdminTopLen || ($nodeLen === $activeAdminTopLen && (int) ($topNode->mm_num ?? 0) < $activeAdminTopNum)) { - $activeAdminTopNav = $topNode; - $activeAdminTopLen = $nodeLen; - $activeAdminTopNum = (int) ($topNode->mm_num ?? 0); - } -} - /** 메뉴가 DB에서 안 쓰일 때만(폴백 상단바) 세그먼트 기반 활성 */ $isActive = static function (string $path) use ($uri, $seg3) { if ($path === 'admin' || $path === '') return $uri === ''; @@ -110,7 +93,15 @@ body { overflow: hidden; } children); $parentLink = menu_link_preferred_href_path($navItem->mm_link ?? null, $currentPath); - $parentIsCurrent = ($activeAdminTopNav !== null && $navItem === $activeAdminTopNav); + $parentIsCurrent = $adminNavItemIsCurrent($navItem->mm_link ?? null); + if (! $parentIsCurrent && $hasChildren) { + foreach ($navItem->children as $ch) { + if ($adminNavItemIsCurrent($ch->mm_link ?? null)) { + $parentIsCurrent = true; + break; + } + } + } ?>