Files
Umbraco-CMS/src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorBlockValidator.cs
Bjarke Berg 0aaac78cfa A bunch of minor performance optimizations (#16335)
* Do not execute query if no macros found

* Request cache the permission lookup

* Unbreak change by adding obsolete ctor

* Clean up

* Wrap indexing for delivery API in a scope

* Do not ask options every time for the timeout, instead listen for updates

* Lookup content types once instead of one by one

* Use TryGetValue instead

* Do a distinct on user ids before building index, to avoid issue with more than 2100 parameters

* Don't map ContentDto (it's unused)

* Introduce request bound block editor element cache

---------

Co-authored-by: kjac <kja@umbraco.dk>
2024-06-03 11:23:25 +02:00

42 lines
1.5 KiB
C#

using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Cache.PropertyEditors;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Core.PropertyEditors;
internal class RichTextEditorBlockValidator : BlockEditorValidatorBase
{
private readonly BlockEditorValues _blockEditorValues;
private readonly IJsonSerializer _jsonSerializer;
private readonly ILogger _logger;
public RichTextEditorBlockValidator(
IPropertyValidationService propertyValidationService,
BlockEditorValues blockEditorValues,
IBlockEditorElementTypeCache elementTypeCache,
IJsonSerializer jsonSerializer,
ILogger logger)
: base(propertyValidationService, elementTypeCache)
{
_blockEditorValues = blockEditorValues;
_jsonSerializer = jsonSerializer;
_logger = logger;
}
protected override IEnumerable<ElementTypeValidationModel> GetElementTypeValidation(object? value)
{
RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue);
if (richTextEditorValue?.Blocks is null)
{
return Array.Empty<ElementTypeValidationModel>();
}
BlockEditorData? blockEditorData = _blockEditorValues.ConvertAndClean(richTextEditorValue.Blocks);
return blockEditorData is not null
? GetBlockEditorDataValidation(blockEditorData)
: Array.Empty<ElementTypeValidationModel>();
}
}