From ecc31a308aa75e32de88a91db7e5017a2ed69acf Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 1 Dec 2023 05:21:09 +1300 Subject: [PATCH] =?UTF-8?q?Added=20BlockEditorDataConverter=20method=20to?= =?UTF-8?q?=20BlockListPropertyEditorBase=20=E2=80=A6=20(#14960)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Blocks/BlockListEditorDataConverter.cs | 19 ++++++++++++++++++- .../BlockListPropertyEditorBase.cs | 12 +++++++++--- .../DataValueEditorReuseTests.cs | 10 ++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Infrastructure/Models/Blocks/BlockListEditorDataConverter.cs b/src/Umbraco.Infrastructure/Models/Blocks/BlockListEditorDataConverter.cs index 9d89b41643..6644ee7fb5 100644 --- a/src/Umbraco.Infrastructure/Models/Blocks/BlockListEditorDataConverter.cs +++ b/src/Umbraco.Infrastructure/Models/Blocks/BlockListEditorDataConverter.cs @@ -6,15 +6,32 @@ using Newtonsoft.Json.Linq; namespace Umbraco.Cms.Core.Models.Blocks; /// -/// Data converter for the block list property editor +/// Handles the conversion of data for the block list property editor. /// public class BlockListEditorDataConverter : BlockEditorDataConverter { + /// + /// Initializes a new instance of the class with a default alias. + /// public BlockListEditorDataConverter() : base(Constants.PropertyEditors.Aliases.BlockList) { } + /// + /// Initializes a new instance of the class with a provided alias. + /// + /// The alias of the property editor. + public BlockListEditorDataConverter(string propertyEditorAlias) + : base(propertyEditorAlias) + { + } + + /// + /// Extracts block references from the provided JSON layout. + /// + /// The JSON layout containing the block references. + /// A collection of objects extracted from the JSON layout. protected override IEnumerable? GetBlockReferences(JToken jsonLayout) { IEnumerable? blockListLayout = jsonLayout.ToObject>(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditorBase.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditorBase.cs index 194383560e..a2f5616518 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditorBase.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditorBase.cs @@ -35,16 +35,22 @@ public abstract class BlockListPropertyEditorBase : DataEditor public override IPropertyIndexValueFactory PropertyIndexValueFactory => _blockValuePropertyIndexValueFactory; - #region Value Editor + /// + /// Instantiates a new for use with the block list editor property value editor. + /// + /// A new instance of . + protected virtual BlockEditorDataConverter CreateBlockEditorDataConverter() => new BlockListEditorDataConverter(); + protected override IDataValueEditor CreateValueEditor() => - DataValueEditorFactory.Create(Attribute!); + DataValueEditorFactory.Create(Attribute!, CreateBlockEditorDataConverter()); internal class BlockListEditorPropertyValueEditor : BlockEditorPropertyValueEditor { public BlockListEditorPropertyValueEditor( DataEditorAttribute attribute, + BlockEditorDataConverter blockEditorDataConverter, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, @@ -56,7 +62,7 @@ public abstract class BlockListPropertyEditorBase : DataEditor IPropertyValidationService propertyValidationService) : base(attribute, propertyEditors, dataTypeService, textService, logger, shortStringHelper, jsonSerializer, ioHelper) { - BlockEditorValues = new BlockEditorValues(new BlockListEditorDataConverter(), contentTypeService, logger); + BlockEditorValues = new BlockEditorValues(blockEditorDataConverter, contentTypeService, logger); Validators.Add(new BlockEditorValidator(propertyValidationService, BlockEditorValues, contentTypeService)); Validators.Add(new MinMaxValidator(BlockEditorValues, textService)); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs index d88a9689ab..67dd5162bf 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs @@ -1,8 +1,9 @@ -using System.Linq; +using System.Linq; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Cms.Core.IO; +using Umbraco.Cms.Core.Models.Blocks; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; @@ -34,9 +35,10 @@ public class DataValueEditorReuseTests _dataValueEditorFactoryMock .Setup(m => - m.Create(It.IsAny())) + m.Create(It.IsAny(), It.IsAny())) .Returns(() => new BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor( new DataEditorAttribute("a", "b", "c"), + new BlockListEditorDataConverter(), _propertyEditorCollection, Mock.Of(), Mock.Of(), @@ -105,7 +107,7 @@ public class DataValueEditorReuseTests Assert.NotNull(dataValueEditor2); Assert.AreNotSame(dataValueEditor1, dataValueEditor2); _dataValueEditorFactoryMock.Verify( - m => m.Create(It.IsAny()), + m => m.Create(It.IsAny(), It.IsAny()), Times.Exactly(2)); } @@ -128,7 +130,7 @@ public class DataValueEditorReuseTests Assert.AreEqual("config", ((DataValueEditor)dataValueEditor2).Configuration); Assert.AreNotSame(dataValueEditor1, dataValueEditor2); _dataValueEditorFactoryMock.Verify( - m => m.Create(It.IsAny()), + m => m.Create(It.IsAny(), It.IsAny()), Times.Exactly(2)); } }