Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@
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>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ protected BlockListPropertyEditorBase(IDataValueEditorFactory dataValueEditorFac

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,
Expand All @@ -56,7 +62,7 @@ public BlockListEditorPropertyValueEditor(
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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,9 +35,10 @@ public void SetUp()

_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>(),
Expand Down Expand Up @@ -105,7 +107,7 @@ public void GetValueEditor_Not_Reusable_Value_Editor_Is_Not_Reused_When_Created_
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));
}

Expand All @@ -128,7 +130,7 @@ public void GetValueEditor_Not_Reusable_Value_Editor_Is_Not_Reused_When_Created_
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));
}
}