From 45e892f3505059674779c6e1a43084a367c2862f Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 6 Feb 2020 16:52:34 +1100 Subject: [PATCH] Changes api to GetData --- .../Models/Blocks/BlockListLayoutReference.cs | 11 +---------- src/Umbraco.Core/Models/Blocks/BlockListModel.cs | 14 +++++++++++++- .../BlockListPropertyValueConverterTests.cs | 11 +++++++---- .../BlockListPropertyValueConverter.cs | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Models/Blocks/BlockListLayoutReference.cs b/src/Umbraco.Core/Models/Blocks/BlockListLayoutReference.cs index 19b30e6ea6..85d17fad24 100644 --- a/src/Umbraco.Core/Models/Blocks/BlockListLayoutReference.cs +++ b/src/Umbraco.Core/Models/Blocks/BlockListLayoutReference.cs @@ -10,10 +10,9 @@ namespace Umbraco.Core.Models.Blocks [DataContract(Name = "blockListLayout", Namespace = "")] public class BlockListLayoutReference : IBlockElement { - public BlockListLayoutReference(Udi udi, IPublishedElement data, IPublishedElement settings) + public BlockListLayoutReference(Udi udi, IPublishedElement settings) { Udi = udi ?? throw new ArgumentNullException(nameof(udi)); - Data = data ?? throw new ArgumentNullException(nameof(data)); Settings = settings; // can be null } @@ -29,13 +28,5 @@ namespace Umbraco.Core.Models.Blocks [DataMember(Name = "settings")] public IPublishedElement Settings { get; } - /// - /// The data item referenced - /// - /// - /// This is ignored from serialization since it is just a reference to the actual data element - /// - [IgnoreDataMember] - public IPublishedElement Data { get; } } } diff --git a/src/Umbraco.Core/Models/Blocks/BlockListModel.cs b/src/Umbraco.Core/Models/Blocks/BlockListModel.cs index 089ca7e6a3..153fe6be8a 100644 --- a/src/Umbraco.Core/Models/Blocks/BlockListModel.cs +++ b/src/Umbraco.Core/Models/Blocks/BlockListModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Runtime.Serialization; using Umbraco.Core.Models.PublishedContent; @@ -22,6 +23,17 @@ namespace Umbraco.Core.Models.Blocks [DataMember(Name = "layout")] public IEnumerable Layout { get; } - + /// + /// Returns the data item associated with the layout udi reference + /// + /// + /// + public IPublishedElement GetData(Udi udi) + { + if (!(udi is GuidUdi guidUdi)) + return null; + return Data.FirstOrDefault(x => x.Key == guidUdi.Guid); + } + } } diff --git a/src/Umbraco.Tests/PropertyEditors/BlockListPropertyValueConverterTests.cs b/src/Umbraco.Tests/PropertyEditors/BlockListPropertyValueConverterTests.cs index ca687f94a6..300c19ac1e 100644 --- a/src/Umbraco.Tests/PropertyEditors/BlockListPropertyValueConverterTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/BlockListPropertyValueConverterTests.cs @@ -317,12 +317,15 @@ data: []}"; Assert.AreEqual(2, converted.Layout.Count()); var item0 = converted.Layout.ElementAt(0); - Assert.AreEqual(Guid.Parse("1304E1DD-AC87-4396-84FE-8A399231CB3D"), item0.Data.Key); - Assert.AreEqual("home", item0.Data.ContentType.Alias); + var item0Data = converted.GetData(item0.Udi); + Assert.IsNotNull(item0Data); + Assert.AreEqual(Guid.Parse("1304E1DD-AC87-4396-84FE-8A399231CB3D"), item0Data.Key); + Assert.AreEqual("home", item0Data.ContentType.Alias); var item1 = converted.Layout.ElementAt(1); - Assert.AreEqual(Guid.Parse("0A4A416E-547D-464F-ABCC-6F345C17809A"), item1.Data.Key); - Assert.AreEqual("home", item1.Data.ContentType.Alias); + var item1Data = converted.GetData(item1.Udi); + Assert.AreEqual(Guid.Parse("0A4A416E-547D-464F-ABCC-6F345C17809A"), item1Data.Key); + Assert.AreEqual("home", item1Data.ContentType.Alias); } diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs index 3878b8d605..3d8e8e2b13 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs @@ -108,7 +108,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters if (!elements.TryGetValue(guidUdi.Guid, out var data)) continue; - var layoutRef = new BlockListLayoutReference(udi, data, element); + var layoutRef = new BlockListLayoutReference(udi, element); layout.Add(layoutRef); }