Skip to content

Commit 0cead6f

Browse files
authored
Fix Rich text block validation path (#18578)
* Made BlockEditorValidator itemDataGroups.Path overridable * PR feedback
1 parent bf7efbc commit 0cead6f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Umbraco.Infrastructure/PropertyEditors/BlockEditorValidatorBase.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ protected IEnumerable<ElementTypeValidationModel> GetBlockEditorDataValidation(B
5151
return elementTypeValidation;
5252
}
5353

54+
protected virtual string ContentDataGroupJsonPath =>
55+
nameof(BlockValue<TLayout>.ContentData).ToFirstLowerInvariant();
56+
57+
protected virtual string SettingsDataGroupJsonPath =>
58+
nameof(BlockValue<TLayout>.SettingsData).ToFirstLowerInvariant();
59+
5460
private IEnumerable<ElementTypeValidationModel> GetBlockEditorDataValidation(BlockEditorData<TValue, TLayout> blockEditorData, string? culture, string? segment)
5561
{
5662
// 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 @@ private IEnumerable<ElementTypeValidationModel> GetBlockEditorDataValidation(Blo
7480

7581
var itemDataGroups = new[]
7682
{
77-
new { Path = nameof(BlockValue<TLayout>.ContentData).ToFirstLowerInvariant(), Items = blockEditorData.BlockValue.ContentData.Where(cd => exposedContentKeys.Contains(cd.Key)).ToArray() },
78-
new { Path = nameof(BlockValue<TLayout>.SettingsData).ToFirstLowerInvariant(), Items = blockEditorData.BlockValue.SettingsData.Where(sd => exposedSettingsKeys.Contains(sd.Key)).ToArray() }
83+
new { Path = ContentDataGroupJsonPath, Items = blockEditorData.BlockValue.ContentData.Where(cd => exposedContentKeys.Contains(cd.Key)).ToArray() },
84+
new { Path = SettingsDataGroupJsonPath, Items = blockEditorData.BlockValue.SettingsData.Where(sd => exposedSettingsKeys.Contains(sd.Key)).ToArray() }
7985
};
8086

8187
var valuesJsonPathPart = nameof(BlockItemData.Values).ToFirstLowerInvariant();

src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Umbraco.Cms.Core.Models.Validation;
55
using Umbraco.Cms.Core.Serialization;
66
using Umbraco.Cms.Core.Services;
7+
using Umbraco.Extensions;
78

89
namespace Umbraco.Cms.Core.PropertyEditors;
910

@@ -26,6 +27,12 @@ public RichTextEditorBlockValidator(
2627
_logger = logger;
2728
}
2829

30+
protected override string ContentDataGroupJsonPath =>
31+
$"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.ContentDataGroupJsonPath}";
32+
33+
protected override string SettingsDataGroupJsonPath =>
34+
$"{nameof(RichTextEditorValue.Blocks).ToFirstLowerInvariant()}.{base.SettingsDataGroupJsonPath}";
35+
2936
protected override IEnumerable<ElementTypeValidationModel> GetElementTypeValidation(object? value, PropertyValidationContext validationContext)
3037
{
3138
RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue);

0 commit comments

Comments
 (0)