Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BlockEditorDataConverter method to BlockListPropertyEditorBase … #14960

Merged
merged 4 commits into from
Nov 30, 2023
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,28 +35,34 @@

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,
ILocalizedTextService textService,
ILogger<BlockEditorPropertyValueEditor> logger,
IShortStringHelper shortStringHelper,
IJsonSerializer jsonSerializer,
IIOHelper ioHelper,
IPropertyValidationService propertyValidationService) :
base(attribute, propertyEditors, dataTypeService, textService, logger, shortStringHelper, jsonSerializer, ioHelper)
{
BlockEditorValues = new BlockEditorValues(new BlockListEditorDataConverter(), contentTypeService, logger);
BlockEditorValues = new BlockEditorValues(blockEditorDataConverter, contentTypeService, logger);

Check notice on line 65 in src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditorBase.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

ℹ Getting worse: Constructor Over-Injection

BlockListEditorPropertyValueEditor increases from 10 to 11 arguments, threshold = 5. This constructor has too many arguments, indicating an object with low cohesion or missing function argument abstraction. Avoid adding more arguments.
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));
}
}
Loading