mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 09:42:29 +08:00
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
This commit is contained in:
committed by
Sipke Schoorstra
parent
3e2b5d5b82
commit
a5ac956b6a
@@ -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 {
|
||||
/// <param name="compareUrls">Should compare raw string URLs instead of route data.</param>
|
||||
/// <returns>A stack with the selection path being the last node the currently selected one.</returns>
|
||||
private static Stack<MenuItem> SetSelectedPath(IEnumerable<MenuItem> menuItems, HttpRequestBase currentRequest, RouteValueDictionary currentRouteData, bool compareUrls) {
|
||||
var selectedPaths = new List<Stack<MenuItem>>();
|
||||
foreach (MenuItem menuItem in menuItems) {
|
||||
Stack<MenuItem> 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<MenuItem>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user