Added BlockEditorDataConverter method to BlockListPropertyEditorBase … (#14960)
This commit is contained in:
@@ -6,15 +6,32 @@ using Newtonsoft.Json.Linq;
|
||||
namespace Umbraco.Cms.Core.Models.Blocks;
|
||||
|
||||
/// <summary>
|
||||
/// Data converter for the block list property editor
|
||||
/// Handles the conversion of data for the block list property editor.
|
||||
/// </summary>
|
||||
public class BlockListEditorDataConverter : BlockEditorDataConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BlockListEditorDataConverter"/> class with a default alias.
|
||||
/// </summary>
|
||||
public BlockListEditorDataConverter()
|
||||
: base(Constants.PropertyEditors.Aliases.BlockList)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BlockListEditorDataConverter"/> class with a provided alias.
|
||||
/// </summary>
|
||||
/// <param name="propertyEditorAlias">The alias of the property editor.</param>
|
||||
public BlockListEditorDataConverter(string propertyEditorAlias)
|
||||
: base(propertyEditorAlias)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts block references from the provided JSON layout.
|
||||
/// </summary>
|
||||
/// <param name="jsonLayout">The JSON layout containing the block references.</param>
|
||||
/// <returns>A collection of <see cref="ContentAndSettingsReference"/> objects extracted from the JSON layout.</returns>
|
||||
protected override IEnumerable<ContentAndSettingsReference>? GetBlockReferences(JToken jsonLayout)
|
||||
{
|
||||
IEnumerable<BlockListLayoutItem>? blockListLayout = jsonLayout.ToObject<IEnumerable<BlockListLayoutItem>>();
|
||||
|
||||
@@ -35,16 +35,22 @@ public abstract class BlockListPropertyEditorBase : DataEditor
|
||||
|
||||
public override IPropertyIndexValueFactory PropertyIndexValueFactory => _blockValuePropertyIndexValueFactory;
|
||||
|
||||
|
||||
#region Value Editor
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new <see cref="BlockEditorDataConverter"/> for use with the block list editor property value editor.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of <see cref="BlockListEditorDataConverter"/>.</returns>
|
||||
protected virtual BlockEditorDataConverter CreateBlockEditorDataConverter() => new BlockListEditorDataConverter();
|
||||
|
||||
protected override IDataValueEditor CreateValueEditor() =>
|
||||
DataValueEditorFactory.Create<BlockListEditorPropertyValueEditor>(Attribute!);
|
||||
DataValueEditorFactory.Create<BlockListEditorPropertyValueEditor>(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));
|
||||
}
|
||||
|
||||
@@ -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<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()))
|
||||
m.Create<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>(), It.IsAny<BlockEditorDataConverter>()))
|
||||
.Returns(() => new BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor(
|
||||
new DataEditorAttribute("a", "b", "c"),
|
||||
new BlockListEditorDataConverter(),
|
||||
_propertyEditorCollection,
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<IContentTypeService>(),
|
||||
@@ -105,7 +107,7 @@ public class DataValueEditorReuseTests
|
||||
Assert.NotNull(dataValueEditor2);
|
||||
Assert.AreNotSame(dataValueEditor1, dataValueEditor2);
|
||||
_dataValueEditorFactoryMock.Verify(
|
||||
m => m.Create<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
m => m.Create<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>(), It.IsAny<BlockEditorDataConverter>()),
|
||||
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<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
m => m.Create<BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>(), It.IsAny<BlockEditorDataConverter>()),
|
||||
Times.Exactly(2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user