From 0cead6f10afcd37fc5de7bc2a3c31230dc274b76 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Wed, 5 Mar 2025 12:42:29 +0100 Subject: [PATCH] Fix Rich text block validation path (#18578) * Made BlockEditorValidator itemDataGroups.Path overridable * PR feedback --- .../PropertyEditors/BlockEditorValidatorBase.cs | 10 ++++++++-- .../PropertyEditors/RichTextEditorBlockValidator.cs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorValidatorBase.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorValidatorBase.cs index d0338f1852..419b84845a 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorValidatorBase.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorValidatorBase.cs @@ -51,6 +51,12 @@ public abstract class BlockEditorValidatorBase : ComplexEditorV return elementTypeValidation; } + protected virtual string ContentDataGroupJsonPath => + nameof(BlockValue.ContentData).ToFirstLowerInvariant(); + + protected virtual string SettingsDataGroupJsonPath => + nameof(BlockValue.SettingsData).ToFirstLowerInvariant(); + private IEnumerable GetBlockEditorDataValidation(BlockEditorData 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 : ComplexEditorV var itemDataGroups = new[] { - new { Path = nameof(BlockValue.ContentData).ToFirstLowerInvariant(), Items = blockEditorData.BlockValue.ContentData.Where(cd => exposedContentKeys.Contains(cd.Key)).ToArray() }, - new { Path = nameof(BlockValue.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(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs index 74428dbd30..a11a11e703 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs @@ -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 + $"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.ContentDataGroupJsonPath}"; + + protected override string SettingsDataGroupJsonPath => + $"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.SettingsDataGroupJsonPath}"; + protected override IEnumerable GetElementTypeValidation(object? value, PropertyValidationContext validationContext) { RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue);