fixes list view ancestor check

This commit is contained in:
Shannon
2015-10-29 12:05:46 +01:00
parent 79f04bf939
commit fbc08d66f1
2 changed files with 23 additions and 2 deletions

View File

@@ -445,6 +445,9 @@ namespace Umbraco.Core.Services
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
public IEnumerable<IContent> GetAncestors(IContent content)
{
//null check otherwise we get exceptions
if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty<IContent>();
var ids = content.Path.Split(',').Where(x => x != Constants.System.Root.ToInvariantString() && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(int.Parse).ToArray();
if (ids.Any() == false)
return new List<IContent>();

View File

@@ -116,8 +116,26 @@ namespace Umbraco.Web.Models.Mapping
{
//map the IsChildOfListView (this is actually if it is a descendant of a list view!)
//TODO: Fix this shorthand .Ancestors() lookup, at least have an overload to use the current
var ancesctorListView = content.Ancestors().FirstOrDefault(x => x.ContentType.IsContainer);
display.IsChildOfListView = ancesctorListView != null;
if (content.HasIdentity)
{
var ancesctorListView = content.Ancestors().FirstOrDefault(x => x.ContentType.IsContainer);
display.IsChildOfListView = ancesctorListView != null;
}
else
{
//it's new so it doesn't have a path, so we need to look this up by it's parent + ancestors
var parent = content.Parent();
if (parent.ContentType.IsContainer)
{
display.IsChildOfListView = true;
}
else
{
var ancesctorListView = parent.Ancestors().FirstOrDefault(x => x.ContentType.IsContainer);
display.IsChildOfListView = ancesctorListView != null;
}
}
//map the tree node url
if (HttpContext.Current != null)