Fix Rich text block validation path (#18578)

* Made BlockEditorValidator itemDataGroups.Path overridable

* PR feedback
This commit is contained in:
Sven Geusens
2025-03-05 12:42:29 +01:00
committed by GitHub
parent bf7efbc268
commit 0cead6f10a
2 changed files with 15 additions and 2 deletions

View File

@@ -51,6 +51,12 @@ public abstract class BlockEditorValidatorBase<TValue, TLayout> : ComplexEditorV
return elementTypeValidation;
}
protected virtual string ContentDataGroupJsonPath =>
nameof(BlockValue<TLayout>.ContentData).ToFirstLowerInvariant();
protected virtual string SettingsDataGroupJsonPath =>
nameof(BlockValue<TLayout>.SettingsData).ToFirstLowerInvariant();
private IEnumerable<ElementTypeValidationModel> GetBlockEditorDataValidation(BlockEditorData<TValue, TLayout> blockEditorData, string? culture, string? segment)
{
// There is no guarantee that the client will post data for every property defined in the Element Type but we still
@@ -74,8 +80,8 @@ public abstract class BlockEditorValidatorBase<TValue, TLayout> : ComplexEditorV
var itemDataGroups = new[]
{
new { Path = nameof(BlockValue<TLayout>.ContentData).ToFirstLowerInvariant(), Items = blockEditorData.BlockValue.ContentData.Where(cd => exposedContentKeys.Contains(cd.Key)).ToArray() },
new { Path = nameof(BlockValue<TLayout>.SettingsData).ToFirstLowerInvariant(), Items = blockEditorData.BlockValue.SettingsData.Where(sd => exposedSettingsKeys.Contains(sd.Key)).ToArray() }
new { Path = ContentDataGroupJsonPath, Items = blockEditorData.BlockValue.ContentData.Where(cd => exposedContentKeys.Contains(cd.Key)).ToArray() },
new { Path = SettingsDataGroupJsonPath, Items = blockEditorData.BlockValue.SettingsData.Where(sd => exposedSettingsKeys.Contains(sd.Key)).ToArray() }
};
var valuesJsonPathPart = nameof(BlockItemData.Values).ToFirstLowerInvariant();

View File

@@ -4,6 +4,7 @@ using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Models.Validation;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.PropertyEditors;
@@ -26,6 +27,12 @@ internal class RichTextEditorBlockValidator: BlockEditorValidatorBase<RichTextBl
_logger = logger;
}
protected override string ContentDataGroupJsonPath =>
$"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.ContentDataGroupJsonPath}";
protected override string SettingsDataGroupJsonPath =>
$"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.SettingsDataGroupJsonPath}";
protected override IEnumerable<ElementTypeValidationModel> GetElementTypeValidation(object? value, PropertyValidationContext validationContext)
{
RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue);