diff --git a/src/Umbraco.Web/Models/DynamicPublishedContent.cs b/src/Umbraco.Web/Models/DynamicPublishedContent.cs index 0cf3ed24a8..875de8a362 100644 --- a/src/Umbraco.Web/Models/DynamicPublishedContent.cs +++ b/src/Umbraco.Web/Models/DynamicPublishedContent.cs @@ -38,6 +38,46 @@ namespace Umbraco.Web.Models private IEnumerable _ownersCollection; + /// + /// Need to get/set the owner collection when an item is returned from the result set of a query + /// + /// + /// Based on this issue here: http://issues.umbraco.org/issue/U4-1797 + /// + IEnumerable IOwnerCollectionAware.OwnersCollection + { + get + { + var publishedContentBase = PublishedContent as IOwnerCollectionAware; + if (publishedContentBase != null) + { + return publishedContentBase.OwnersCollection; + } + + //if the owners collection is null, we'll default to it's siblings + if (_ownersCollection == null) + { + //get the root docs if parent is null + _ownersCollection = this.Siblings(); + } + return _ownersCollection; + } + set + { + var publishedContentBase = PublishedContent as IOwnerCollectionAware; + if (publishedContentBase != null) + { + publishedContentBase.OwnersCollection = value; + } + else + { + _ownersCollection = value; + } + } + } + + private IEnumerable _ownersCollection; + /// /// Need to get/set the owner collection when an item is returned from the result set of a query /// diff --git a/src/Umbraco.Web/Models/XmlPublishedContent.cs b/src/Umbraco.Web/Models/XmlPublishedContent.cs index 867fc8c144..299d3bf083 100644 --- a/src/Umbraco.Web/Models/XmlPublishedContent.cs +++ b/src/Umbraco.Web/Models/XmlPublishedContent.cs @@ -44,6 +44,29 @@ namespace Umbraco.Web.Models Initialize(); } + private IEnumerable _ownersCollection; + + /// + /// Need to get/set the owner collection when an item is returned from the result set of a query + /// + /// + /// Based on this issue here: http://issues.umbraco.org/issue/U4-1797 + /// + IEnumerable IOwnerCollectionAware.OwnersCollection + { + get + { + //if the owners collection is null, we'll default to it's siblings + if (_ownersCollection == null) + { + //get the root docs if parent is null + _ownersCollection = this.Siblings(); + } + return _ownersCollection; + } + set { _ownersCollection = value; } + } + private bool _initialized = false; private readonly ICollection _children = new Collection(); private IPublishedContent _parent = null; diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 82b7959ee1..1fb0271681 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -781,6 +781,30 @@ namespace Umbraco.Web { return test(content) ? new HtmlString(valueIfTrue) : new HtmlString(valueIfFalse); } + + /// + /// Return the owners collection of the current content item. + /// + /// + /// + /// + /// If the content item is of type PublishedContentBase we will have a property called OwnersCollection which will + /// be the collection of a resultant set (i.e. from a where clause, a call to Children(), etc...) otherwise it will + /// be the item's siblings. All relates to this issue: http://issues.umbraco.org/issue/U4-1797 + /// + private static IEnumerable GetOwnersList(this IPublishedContent content) + { + //Here we need to type check, we need to see if we have a real OwnersCollection list based on the result set + // of a query, otherwise we can only lookup among the item's siblings. All related to this issue here: + // http://issues.umbraco.org/issue/U4-1797 + + var publishedContentBase = content as IOwnerCollectionAware; + var ownersList = publishedContentBase != null + ? publishedContentBase.OwnersCollection + : content.Siblings(); + return ownersList; + } + #endregion #region Ancestors