diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs index 676eb05ef0..a0fa7932b5 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs @@ -44,6 +44,11 @@ namespace Umbraco.Core.Models.PublishedContent InitializeIndexes(); } + // create detached content type - ie does not match anything in the DB + internal PublishedContentType(string alias, IEnumerable propertyTypes) + : this (0, alias, propertyTypes) + { } + private void InitializeIndexes() { for (var i = 0; i < _propertyTypes.Length; i++) diff --git a/src/Umbraco.Web/Models/DetachedContent.cs b/src/Umbraco.Web/Models/DetachedContent.cs index e572de656c..b00ff67c72 100644 --- a/src/Umbraco.Web/Models/DetachedContent.cs +++ b/src/Umbraco.Web/Models/DetachedContent.cs @@ -10,21 +10,36 @@ namespace Umbraco.Web.Models { private readonly Dictionary _properties; + /// + /// Initialized a new instance of the class with properties. + /// + /// The properties + /// Properties must be detached or nested properties ie their property type must be detached or nested. + /// Such a detached content can be part of a published property value. public DetachedContent(IEnumerable properties) { - _properties = properties.ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); + var propsa = properties.ToArray(); + if (propsa.Any(x => x.PropertyType.IsDetachedOrNested == false)) + throw new ArgumentException("At least one property type is neither detached nor nested.", "properties"); + _properties = propsa.ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); } + // don't uncomment until you know what you are doing + /* public DetachedContent(IPublishedContent content) { _properties = content.Properties.ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); } + */ + // don't uncomment until you know what you are doing + // at the moment, I don't fully + /* public DetachedContent(IContent content, bool isPreviewing) { var publishedContentType = PublishedContentType.Get(PublishedItemType.Content, content.ContentType.Alias); _properties = PublishedProperty.MapProperties(publishedContentType.PropertyTypes, content.Properties, - (t, v) => PublishedProperty.GetDetached(t, v, isPreviewing)) + (t, v) => PublishedProperty.GetDetached(t.Detached(), v, isPreviewing)) .ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); } @@ -32,7 +47,7 @@ namespace Umbraco.Web.Models { var publishedContentType = PublishedContentType.Get(PublishedItemType.Media, media.ContentType.Alias); _properties = PublishedProperty.MapProperties(publishedContentType.PropertyTypes, media.Properties, - (t, v) => PublishedProperty.GetDetached(t, v, isPreviewing)) + (t, v) => PublishedProperty.GetDetached(t.Detached(), v, isPreviewing)) .ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); } @@ -40,9 +55,10 @@ namespace Umbraco.Web.Models { var publishedContentType = PublishedContentType.Get(PublishedItemType.Member, member.ContentType.Alias); _properties = PublishedProperty.MapProperties(publishedContentType.PropertyTypes, member.Properties, - (t, v) => PublishedProperty.GetDetached(t, v, isPreviewing)) + (t, v) => PublishedProperty.GetDetached(t.Detached(), v, isPreviewing)) .ToDictionary(x => x.PropertyTypeAlias, x => x, StringComparer.InvariantCultureIgnoreCase); } + */ public ICollection Properties { diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index bfa57d5ab3..a0cff38414 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -437,8 +437,9 @@ namespace Umbraco.Web //currently assigned node. The PublishedContentRequest will be null if: // * we are rendering a partial view or child action // * we are rendering a view from a custom route - if (UmbracoContext.PublishedContentRequest == null + if ((UmbracoContext.PublishedContentRequest == null || UmbracoContext.PublishedContentRequest.PublishedContent.Id != currentPage.Id) + && currentPage.Id > 0) // in case we're rendering a detached content (id == 0) { item.NodeId = currentPage.Id.ToString(); }