Skip to content

Commit

Permalink
#82 Support for Sort order on Content Type Allowed Items
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Feb 24, 2020
1 parent 3902f00 commit b92f1b0
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ protected XElement SerializeStructure(TObject item)
var node = new XElement("Structure");
List<KeyValuePair<string, string>> items = new List<KeyValuePair<string, string>>();

foreach (var allowedType in item.AllowedContentTypes)
foreach (var allowedType in item.AllowedContentTypes.OrderBy(x => x.SortOrder))
{
var allowedItem = FindItem(allowedType.Id.Value);
if (allowedItem != null)
{
items.Add(new KeyValuePair<string, string>(allowedItem.Key.ToString(), allowedItem.Alias));
node.Add(new XElement(ItemType,
new XAttribute("Key", allowedItem.Key),
new XAttribute("SortOrder", allowedItem.SortOrder), allowedItem.Alias));
}
}
if (items.Count > 0)
node.Add(items.OrderBy(x => x.Value).Select(x => new XElement(ItemType, new XAttribute("Key", x.Key), x.Value)).ToArray());
return node;
}

Expand Down Expand Up @@ -223,6 +223,8 @@ protected void DeserializeStructure(TObject item, XElement node)

logger.Debug(serializerType, "Structure: {0}", key);

var itemSortOrder = baseNode.Attribute("SortOrder").ValueOrDefault(sortOrder);

IContentTypeBase baseItem = default(IContentTypeBase);

if (key != Guid.Empty)
Expand All @@ -244,9 +246,9 @@ protected void DeserializeStructure(TObject item, XElement node)
logger.Debug(serializerType, "Structure Found {0}", baseItem.Alias);

allowed.Add(new ContentTypeSort(
new Lazy<int>(() => baseItem.Id), sortOrder, baseItem.Alias));
new Lazy<int>(() => baseItem.Id), itemSortOrder, baseItem.Alias));

sortOrder++;
sortOrder = itemSortOrder + 1;
}
}

Expand Down

0 comments on commit b92f1b0

Please sign in to comment.