From fbc08d66f1ce98caec5eec6ba1bdc7c2dfd4d58f Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 29 Oct 2015 12:05:46 +0100 Subject: [PATCH] fixes list view ancestor check --- src/Umbraco.Core/Services/ContentService.cs | 3 +++ .../Models/Mapping/ContentModelMapper.cs | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index da25bd0938..ba8b51fa5b 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -445,6 +445,9 @@ namespace Umbraco.Core.Services /// An Enumerable list of objects public IEnumerable GetAncestors(IContent content) { + //null check otherwise we get exceptions + if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty(); + 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(); diff --git a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs index 2e524fc480..d733ccd946 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs @@ -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)