Fixing navigation hierarchy building

--HG--
branch : 1.5.x
This commit is contained in:
Sebastien Ros 2012-07-19 13:41:42 -07:00
parent 76bb42cff2
commit 1926af7ca4

View File

@ -196,27 +196,24 @@ namespace Orchard.UI.Navigation {
foreach (var item in items) {
MenuItem parent = null;
var position = item.Position;
var parentPosition = String.Empty;
while (parent == null && !String.IsNullOrEmpty(position)) {
if (index.TryGetValue(position, out parent)) {
parent.Items = parent.Items.Concat(new [] { item });
}
var lastSegment = item.Position.LastIndexOf('.');
if (lastSegment != -1) {
parentPosition = item.Position.Substring(0, lastSegment);
}
position = position.Substring(0, position.Length - 1);
};
if (index.TryGetValue(parentPosition, out parent)) {
parent.Items = parent.Items.Concat(new [] { item });
}
else {
result.Add(item);
}
if (!index.ContainsKey(item.Position)) {
// prevent invalid positions
index.Add(item.Position, item);
}
// if the current element has no parent, it's a top level item
if (parent == null) {
result.Add(item);
}
}
return result;