From a5ac956b6a3490539b496f2602ee1d1ac13ce2cf Mon Sep 17 00:00:00 2001 From: Alex Petryakov Date: Thu, 16 Jun 2016 22:52:51 +0300 Subject: [PATCH] Fixes a selected path issue This fixes an issue where the selected path is being looked for by comparing string-based urls. It now selects the most nested url. #6899 --- src/Orchard/UI/Navigation/NavigationHelper.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Orchard/UI/Navigation/NavigationHelper.cs b/src/Orchard/UI/Navigation/NavigationHelper.cs index b6cb0faa8..2ab551c97 100644 --- a/src/Orchard/UI/Navigation/NavigationHelper.cs +++ b/src/Orchard/UI/Navigation/NavigationHelper.cs @@ -84,6 +84,12 @@ namespace Orchard.UI.Navigation { var path = SetSelectedPath(menuItems, currentRequest, currentRouteData, false) ?? SetSelectedPath(menuItems, currentRequest, currentRouteData, true); + if(path != null) { + foreach(var menuItem in path) { + menuItem.Selected = true; + } + } + return path; } @@ -96,12 +102,17 @@ namespace Orchard.UI.Navigation { /// Should compare raw string URLs instead of route data. /// A stack with the selection path being the last node the currently selected one. private static Stack SetSelectedPath(IEnumerable menuItems, HttpRequestBase currentRequest, RouteValueDictionary currentRouteData, bool compareUrls) { + var selectedPaths = new List>(); foreach (MenuItem menuItem in menuItems) { Stack selectedPath = SetSelectedPath(menuItem.Items, currentRequest, currentRouteData, compareUrls); if (selectedPath != null) { - menuItem.Selected = true; selectedPath.Push(menuItem); - return selectedPath; + if (compareUrls) { + selectedPaths.Add(selectedPath); + } + else { + return selectedPath; + } } // compare route values (if any) first @@ -122,15 +133,19 @@ namespace Orchard.UI.Navigation { } if (match) { - menuItem.Selected = true; - selectedPath = new Stack(); selectedPath.Push(menuItem); - return selectedPath; + + if (compareUrls) { + selectedPaths.Add(selectedPath); + } + else { + return selectedPath; + } } } - return null; + return selectedPaths.OrderByDescending(p => p.First().Href.Split('/').Length).FirstOrDefault(); } ///