From 2270188668a729da770f4e8a5eedb44747b5f1c5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 22 Apr 2019 15:39:24 +0200 Subject: [PATCH] Refactor IPublishedContent.Children() --- .../PublishedContent/IPublishedContent.cs | 9 +++++-- .../PublishedContentWrapped.cs | 2 +- .../PublishedMediaCacheTests.cs | 12 +++++----- .../DictionaryPublishedContent.cs | 2 +- .../XmlPublishedContent.cs | 9 +++---- .../Published/NestedContentTests.cs | 2 +- .../PublishedContentDataTableTests.cs | 7 ++---- .../PublishedContentLanguageVariantTests.cs | 24 +++++++++---------- .../PublishedContent/PublishedContentTests.cs | 20 ++++++++-------- .../SolidPublishedSnapshot.cs | 4 +++- .../TestHelpers/Stubs/TestPublishedContent.cs | 4 +++- .../ListChildPagesFromChangeableSource.cshtml | 2 +- .../ListChildPagesFromCurrentPage.cshtml | 2 +- .../ListChildPagesOrderedByDate.cshtml | 2 +- .../ListChildPagesOrderedByName.cshtml | 2 +- .../ListChildPagesOrderedByProperty.cshtml | 2 +- .../ListDescendantsFromCurrentPage.cshtml | 6 ++--- .../ListImagesFromMediaFolder.cshtml | 2 +- .../Templates/Navigation.cshtml | 2 +- .../Templates/SiteMap.cshtml | 2 +- .../PublishedContentHashtableConverter.cs | 2 +- .../Models/PublishedContentBase.cs | 2 +- .../PublishedCache/NuCache/ContentCache.cs | 4 ++-- .../NuCache/PublishedContent.cs | 19 ++++++++------- .../PublishedCache/PublishedMember.cs | 2 +- src/Umbraco.Web/PublishedContentExtensions.cs | 5 ++-- 26 files changed, 78 insertions(+), 73 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs index 7f15e367c8..a6482b48ab 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs @@ -160,8 +160,13 @@ namespace Umbraco.Core.Models.PublishedContent /// /// Gets the children of the content item. /// - /// Children are sorted by their sortOrder. - IEnumerable Children { get; } + /// The specific culture to get the url children for. If null is used the current culture is used (Default is null). + /// + /// Gets children that are available for the specified culture. + /// Children are sorted by their sortOrder. + /// + // FIXME: can culture be '*'? + IEnumerable Children(string culture = null); #endregion } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs index d0db4d6e09..5bac22ad24 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs @@ -116,7 +116,7 @@ namespace Umbraco.Core.Models.PublishedContent public virtual IPublishedContent Parent() => _content.Parent(); /// - public virtual IEnumerable Children => _content.Children; + public virtual IEnumerable Children(string culture = null) => _content.Children(culture); #endregion diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index ce89310f35..bcd34ef2e3 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -172,9 +172,9 @@ namespace Umbraco.Tests.Cache.PublishedCache child1, child2 }); - Assert.AreEqual(2, dicDoc.Children.Count()); - Assert.AreEqual(222333, dicDoc.Children.ElementAt(0).Id); - Assert.AreEqual(444555, dicDoc.Children.ElementAt(1).Id); + Assert.AreEqual(2, dicDoc.Children().Count()); + Assert.AreEqual(222333, dicDoc.Children().ElementAt(0).Id); + Assert.AreEqual(444555, dicDoc.Children().ElementAt(1).Id); } [Test] @@ -229,9 +229,9 @@ namespace Umbraco.Tests.Cache.PublishedCache DoAssert(doc, 2000, key, null, 2, "image1", "Image", 23, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1); Assert.AreEqual(null, doc.Parent()); - Assert.AreEqual(2, doc.Children.Count()); - Assert.AreEqual(2001, doc.Children.ElementAt(0).Id); - Assert.AreEqual(2002, doc.Children.ElementAt(1).Id); + Assert.AreEqual(2, doc.Children().Count()); + Assert.AreEqual(2001, doc.Children().ElementAt(0).Id); + Assert.AreEqual(2002, doc.Children().ElementAt(1).Id); } private XmlDocument GetMediaXml() diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs index 3175d0aca0..cd362cadc0 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs @@ -183,7 +183,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache public override IEnumerable Properties => _properties; - public override IEnumerable Children => _getChildren.Value; + public override IEnumerable Children(string culture = null) => _getChildren.Value; public override IPublishedProperty GetProperty(string alias) { diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs index 8981b6c691..bc9ab8010d 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs @@ -75,13 +75,10 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache private bool _isDraft; - public override IEnumerable Children + public override IEnumerable Children(string culture = null) { - get - { - EnsureNodeInitialized(andChildren: true); - return _children; - } + EnsureNodeInitialized(andChildren: true); + return _children; } public override IPublishedProperty GetProperty(string alias) diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index 31fac026f9..8b954d6ab0 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -275,7 +275,7 @@ namespace Umbraco.Tests.Published public override bool IsDraft(string culture = null) => false; public override bool IsPublished(string culture = null) => true; public override IPublishedContent Parent() => null; - public override IEnumerable Children { get; } + public override IEnumerable Children(string culture = null) => Enumerable.Empty(); public override IPublishedContentType ContentType { get; } // ReSharper restore UnassignedGetOnlyAutoProperty diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs index 7dddd76b8e..077dfd3c94 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs @@ -97,7 +97,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetContent(true, 1); //change a doc type alias - var c = (TestPublishedContent)doc.Children.ElementAt(0); + var c = (TestPublishedContent)doc.Children().ElementAt(0); c.ContentType = new PublishedContentType(22, "DontMatch", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing); var dt = doc.ChildrenAsTable(Current.Services, "Child"); @@ -190,10 +190,7 @@ namespace Umbraco.Tests.PublishedContent IPublishedContent IPublishedContent.Parent() => Parent; - IEnumerable IPublishedContent.Children - { - get { return Children; } - } + IEnumerable IPublishedContent.Children(string culture = null) => Children; public IPublishedContent Parent { get; set; } public int Id { get; set; } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs index 0b549d51ef..4fe028b1db 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs @@ -177,10 +177,10 @@ namespace Umbraco.Tests.PublishedContent item3.SetUrlSegment("content-3"); item3.SetUrl("/content-1/content-2/content-3"); - item1.Children = new List { item2 }; + item1.SetChildren(new List { item2 }); item2.SetParent(item1); - item2.Children = new List { item3 }; + item2.SetChildren(new List { item3 }); item3.SetParent(item2); cache.Add(item1); @@ -247,7 +247,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_Recursively_Unless_Requested() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); var value = content.Value("welcomeText2"); Assert.IsNull(value); } @@ -255,7 +255,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); } @@ -263,7 +263,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_Recursively_Unless_Requested2() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First().Children().First(); Assert.IsNull(content.GetProperty("welcomeText2")); var value = content.Value("welcomeText2"); Assert.IsNull(value); @@ -272,7 +272,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively2() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First().Children().First(); Assert.IsNull(content.GetProperty("welcomeText2")); var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); @@ -281,7 +281,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively3() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First().Children().First(); Assert.IsNull(content.GetProperty("noprop")); var value = content.Value("noprop", fallback: Fallback.ToAncestors); // property has no value but we still get the value (ie, the converter would do something) @@ -292,7 +292,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_With_Recursive_Priority() { Current.VariationContextAccessor.VariationContext = new VariationContext("nl"); - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); var value = content.Value("welcomeText", "nl", fallback: Fallback.To(Fallback.Ancestors, Fallback.Language)); @@ -303,7 +303,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_With_Fallback_Language_Priority() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); var value = content.Value("welcomeText", "nl", fallback: Fallback.ToLanguage); // No Dutch value is directly assigned. Check has fallen back to English value from language variant. @@ -313,14 +313,14 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Throws_For_Non_Supported_Fallback() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); Assert.Throws(() => content.Value("welcomeText", "nl", fallback: Fallback.To(999))); } [Test] public void Can_Fallback_To_Default_Value() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); // no Dutch value is assigned, so getting null var value = content.Value("welcomeText", "nl"); @@ -338,7 +338,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Have_Custom_Default_Value() { - var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children().First(); // HACK: the value, pretend the converter would return something var prop = content.GetProperty("welcomeText") as SolidPublishedPropertyWithLanguageVariants; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 8be13345fb..4472842251 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -169,7 +169,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var items = doc.Children.Where(x => x.IsVisible()).ToIndexedArray(); + var items = doc.Children().Where(x => x.IsVisible()).ToIndexedArray(); foreach (var item in items) { @@ -190,7 +190,7 @@ namespace Umbraco.Tests.PublishedContent var doc = GetNode(1173); var items = doc - .Children + .Children() .Where(x => x.IsVisible()) .ToIndexedArray(); @@ -245,7 +245,7 @@ namespace Umbraco.Tests.PublishedContent var doc = GetNode(1173); var ct = doc.ContentType; - var items = doc.Children + var items = doc.Children() .Select(x => x.CreateModel()) // linq, returns IEnumerable // only way around this is to make sure every IEnumerable extension @@ -277,7 +277,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var items = doc.Children.Take(4).ToIndexedArray(); + var items = doc.Children().Take(4).ToIndexedArray(); foreach (var item in items) { @@ -297,7 +297,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - foreach (var d in doc.Children.Skip(1).ToIndexedArray()) + foreach (var d in doc.Children().Skip(1).ToIndexedArray()) { if (d.Content.Id != 1176) { @@ -315,7 +315,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var items = doc.Children + var items = doc.Children() .Concat(new[] { GetNode(1175), GetNode(4444) }) .ToIndexedArray(); @@ -400,7 +400,7 @@ namespace Umbraco.Tests.PublishedContent var doc = GetNode(1046); - var found1 = doc.Children.GroupBy(x => x.ContentType.Alias).ToArray(); + var found1 = doc.Children().GroupBy(x => x.ContentType.Alias).ToArray(); Assert.AreEqual(2, found1.Length); Assert.AreEqual(2, found1.Single(x => x.Key.ToString() == "Home").Count()); @@ -421,8 +421,8 @@ namespace Umbraco.Tests.PublishedContent var doc = GetNode(1046); - var found1 = doc.Children.Where(x => x.ContentType.Alias == "CustomDocument"); - var found2 = doc.Children.Where(x => x.ContentType.Alias == "Home"); + var found1 = doc.Children().Where(x => x.ContentType.Alias == "CustomDocument"); + var found2 = doc.Children().Where(x => x.ContentType.Alias == "Home"); Assert.AreEqual(1, found1.Count()); Assert.AreEqual(2, found2.Count()); @@ -433,7 +433,7 @@ namespace Umbraco.Tests.PublishedContent { var doc = GetNode(1173); - var ordered = doc.Children.OrderBy(x => x.UpdateDate); + var ordered = doc.Children().OrderBy(x => x.UpdateDate); var correctOrder = new[] { 1178, 1177, 1174, 1176 }; for (var i = 0; i < correctOrder.Length; i++) diff --git a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs index de9f82c6f7..d61dead9c2 100644 --- a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs +++ b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs @@ -212,7 +212,9 @@ namespace Umbraco.Tests.PublishedContent private IPublishedContent _parent; public IPublishedContent Parent() => _parent; public void SetParent(IPublishedContent parent) => _parent = parent; - public IEnumerable Children { get; set; } + private IEnumerable _children; + public IEnumerable Children(string culture = null) => _children; + public void SetChildren(IEnumerable children) => _children = children; #endregion diff --git a/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs b/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs index 4334e24f6d..8c631bb067 100644 --- a/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs +++ b/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs @@ -56,7 +56,9 @@ namespace Umbraco.Tests.TestHelpers.Stubs private IPublishedContent _parent; public IPublishedContent Parent() => _parent; public void SetParent(IPublishedContent parent) => _parent = parent; - public IEnumerable Children { get; set; } + private IEnumerable _children; + public IEnumerable Children(string culture = null) => _children; + public void SetChildren(IEnumerable children) => _children = children; // copied from PublishedContentBase public IPublishedProperty GetProperty(string alias, bool recurse) diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromChangeableSource.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromChangeableSource.cshtml index 46c8de695c..495141f821 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromChangeableSource.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromChangeableSource.cshtml @@ -19,7 +19,7 @@ { @* Get the starting page *@ var startNode = Umbraco.Content(startNodeId); - var selection = startNode.Children.Where(x => x.IsVisible()).ToArray(); + var selection = startNode.Children().Where(x => x.IsVisible()).ToArray(); if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromCurrentPage.cshtml index e6606d6204..6ba7471899 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromCurrentPage.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesFromCurrentPage.cshtml @@ -9,7 +9,7 @@ - It then generates links so the visitor can go to each page *@ -@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).ToArray(); } +@{ var selection = Model.Content.Children().Where(x => x.IsVisible()).ToArray(); } @if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByDate.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByDate.cshtml index 2c2cc4422b..4ace3da7d1 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByDate.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByDate.cshtml @@ -10,7 +10,7 @@ - It then generates links so the visitor can go to each page *@ -@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate).ToArray(); } +@{ var selection = Model.Content.Children().Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate).ToArray(); } @if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByName.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByName.cshtml index d0398e7272..ecfd8ebe9d 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByName.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByName.cshtml @@ -10,7 +10,7 @@ - It then generates links so the visitor can go to each page *@ -@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderBy(x => x.Name).ToArray(); } +@{ var selection = Model.Content.Children().Where(x => x.IsVisible()).OrderBy(x => x.Name).ToArray(); } @if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByProperty.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByProperty.cshtml index 1bffae04c4..667a384dfe 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByProperty.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListChildPagesOrderedByProperty.cshtml @@ -17,7 +17,7 @@ @if (propertyAlias != null) { - var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderBy(x => x.Value(propertyAlias.ToString())).ToArray(); + var selection = Model.Content.Children().Where(x => x.IsVisible()).OrderBy(x => x.Value(propertyAlias.ToString())).ToArray(); if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListDescendantsFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListDescendantsFromCurrentPage.cshtml index 7ae917b41d..196db52d92 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListDescendantsFromCurrentPage.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListDescendantsFromCurrentPage.cshtml @@ -7,7 +7,7 @@ the page currently being viewed by the website visitor, displayed as nested unordered HTML lists. *@ -@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).ToArray(); } +@{ var selection = Model.Content.Children().Where(x => x.IsVisible()).ToArray(); } @* Ensure that the Current Page has children *@ @if (selection.Length > 0) @@ -25,7 +25,7 @@ @* if this child page has any children, where the property umbracoNaviHide is not True *@ @{ - var children = item.Children.Where(x => x.IsVisible()).ToArray(); + var children = item.Children().Where(x => x.IsVisible()).ToArray(); if (children.Length > 0) { @* Call our helper to display the children *@ @@ -54,7 +54,7 @@ @* if the page has any children, where the property umbracoNaviHide is not True *@ @{ - var children = item.Children.Where(x => x.IsVisible()).ToArray(); + var children = item.Children().Where(x => x.IsVisible()).ToArray(); if (children.Length > 0) { @* Recurse and call our helper to display the children *@ diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml index 51fdbadb00..b6067ff93a 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml @@ -18,7 +18,7 @@ { @* Get the media item associated with the id passed in *@ var media = Umbraco.Media(mediaId); - var selection = media.Children.ToArray(); + var selection = media.Children().ToArray(); if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml index 1c01eeb855..733c6be801 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml @@ -7,7 +7,7 @@ It also highlights the current active page/section in the navigation with the CSS class "current". *@ -@{ var selection = Model.Content.Root().Children.Where(x => x.IsVisible()).ToArray(); } +@{ var selection = Model.Content.Root().Children().Where(x => x.IsVisible()).ToArray(); } @if (selection.Length > 0) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml index 567ed5d07d..a14d6fdc09 100755 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml @@ -23,7 +23,7 @@ const int maxLevelForSitemap = 4; @* Select visible children *@ - var selection = node.Children.Where(x => x.IsVisible() && x.Level <= maxLevelForSitemap).ToArray(); + var selection = node.Children().Where(x => x.IsVisible() && x.Level <= maxLevelForSitemap).ToArray(); @* If any items are returned, render a list *@ if (selection.Length > 0) diff --git a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs index 209808e282..ebeafd2c06 100644 --- a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs +++ b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs @@ -290,7 +290,7 @@ namespace Umbraco.Web.Macros public IPublishedContent Parent() => _parent; - public IEnumerable Children => throw new NotImplementedException(); + public IEnumerable Children(string culture = null) => throw new NotImplementedException(); public IEnumerable Properties => _properties; diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index d2b3a3749b..f29dc48d2b 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -154,7 +154,7 @@ namespace Umbraco.Web.Models public abstract IPublishedContent Parent(); /// - public abstract IEnumerable Children { get; } + public abstract IEnumerable Children(string culture = null); #endregion diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs index c364f5788a..e422c04f72 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs @@ -107,7 +107,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // hideTopLevelNode = support legacy stuff, look for /*/path/to/node // else normal, look for /path/to/node content = hideTopLevelNode.Value - ? GetAtRoot(preview).SelectMany(x => x.Children).FirstOrDefault(x => x.UrlSegment(culture) == parts[0]) + ? GetAtRoot(preview).SelectMany(x => x.Children(culture)).FirstOrDefault(x => x.UrlSegment(culture) == parts[0]) : GetAtRoot(preview).FirstOrDefault(x => x.UrlSegment(culture) == parts[0]); content = FollowRoute(content, parts, 1, culture); } @@ -187,7 +187,7 @@ namespace Umbraco.Web.PublishedCache.NuCache while (content != null && i < parts.Count) { var part = parts[i++]; - content = content.Children.FirstOrDefault(x => + content = content.Children(culture).FirstOrDefault(x => { var urlSegment = x.UrlSegment(culture); return urlSegment == part; diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index a854a8a2ad..c1215c881b 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -341,17 +341,18 @@ namespace Umbraco.Web.PublishedCache.NuCache } /// - public override IEnumerable Children + public override IEnumerable Children(string culture = null) { - get - { - var cache = GetAppropriateCache(); - if (cache == null || PublishedSnapshotService.CachePublishedContentChildren == false) - return GetChildren(); + // FIXME THIS CANNOT WORK + // we cannot cache children this way, they should be a linked list! + throw new NotImplementedException(); - // note: ToArray is important here, we want to cache the result, not the function! - return (IEnumerable)cache.Get(ChildrenCacheKey, () => GetChildren().ToArray()); - } + var cache = GetAppropriateCache(); + if (cache == null || PublishedSnapshotService.CachePublishedContentChildren == false) + return GetChildren(); + + // note: ToArray is important here, we want to cache the result, not the function! + return (IEnumerable)cache.Get(ChildrenCacheKey, () => GetChildren().ToArray()); } private string _childrenCacheKey; diff --git a/src/Umbraco.Web/PublishedCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/PublishedMember.cs index 09d01229f3..f0c3ac4f5b 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedMember.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedMember.cs @@ -84,7 +84,7 @@ namespace Umbraco.Web.PublishedCache public override IPublishedContent Parent() => null; - public override IEnumerable Children => Enumerable.Empty(); + public override IEnumerable Children(string culture = null) => Enumerable.Empty(); public override IEnumerable Properties => _properties; diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 708c9a8e09..15d4432a90 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -891,6 +891,7 @@ namespace Umbraco.Web #region Axes: children + // FIXME: kill that one /// /// Gets the children of the content. /// @@ -905,7 +906,7 @@ namespace Umbraco.Web { if (content == null) throw new ArgumentNullException(nameof(content)); - return content.Children.WhereIsInvariantOrHasCulture(culture); + return content.Children(culture); //.WhereIsInvariantOrHasCulture(culture); } /// @@ -1029,7 +1030,7 @@ namespace Umbraco.Web //create all row data var tableData = Core.DataTableExtensions.CreateTableData(); //loop through each child and create row data for it - foreach (var n in content.Children.OrderBy(x => x.SortOrder)) + foreach (var n in content.Children().OrderBy(x => x.SortOrder)) { if (contentTypeAliasFilter.IsNullOrWhiteSpace() == false) {