diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index ef0e25204c60..83f43e099cd0 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -240,6 +240,7 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); return builder; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs index 772e72283377..902f9da3c24f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs @@ -176,6 +176,7 @@ internal class RichTextPropertyValueEditor : BlockValuePropertyValueEditorBase private readonly IJsonSerializer _jsonSerializer; private readonly IBlockEditorElementTypeCache _elementTypeCache; private readonly IRichTextRequiredValidator _richTextRequiredValidator; + private readonly IRichTextRegexValidator _richTextRegexValidator; private readonly ILogger _logger; [Obsolete("Use non-obsolete constructor. This is schedules for removal in v16.")] @@ -215,10 +216,11 @@ public RichTextPropertyValueEditor( elementTypeCache, propertyValidationService, dataValueReferenceFactoryCollection, - StaticServiceProvider.Instance.GetRequiredService()) + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) { - } + public RichTextPropertyValueEditor( DataEditorAttribute attribute, PropertyEditorCollection propertyEditors, @@ -238,6 +240,49 @@ public RichTextPropertyValueEditor( IPropertyValidationService propertyValidationService, DataValueReferenceFactoryCollection dataValueReferenceFactoryCollection, IRichTextRequiredValidator richTextRequiredValidator) + : this( + attribute, + propertyEditors, + dataTypeReadCache, + logger, + backOfficeSecurityAccessor, + localizedTextService, + shortStringHelper, + imageSourceParser, + localLinkParser, + pastedImages, + jsonSerializer, + ioHelper, + htmlSanitizer, + macroParameterParser, + elementTypeCache, + propertyValidationService, + dataValueReferenceFactoryCollection, + richTextRequiredValidator, + StaticServiceProvider.Instance.GetRequiredService()) + { + } + + public RichTextPropertyValueEditor( + DataEditorAttribute attribute, + PropertyEditorCollection propertyEditors, + IDataTypeConfigurationCache dataTypeReadCache, + ILogger logger, + IBackOfficeSecurityAccessor backOfficeSecurityAccessor, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper, + HtmlImageSourceParser imageSourceParser, + HtmlLocalLinkParser localLinkParser, + RichTextEditorPastedImages pastedImages, + IJsonSerializer jsonSerializer, + IIOHelper ioHelper, + IHtmlSanitizer htmlSanitizer, + IHtmlMacroParameterParser macroParameterParser, + IBlockEditorElementTypeCache elementTypeCache, + IPropertyValidationService propertyValidationService, + DataValueReferenceFactoryCollection dataValueReferenceFactoryCollection, + IRichTextRequiredValidator richTextRequiredValidator, + IRichTextRegexValidator richTextRegexValidator) : base(attribute, propertyEditors, dataTypeReadCache, localizedTextService, logger, shortStringHelper, jsonSerializer, ioHelper, dataValueReferenceFactoryCollection) { _backOfficeSecurityAccessor = backOfficeSecurityAccessor; @@ -249,6 +294,7 @@ public RichTextPropertyValueEditor( _macroParameterParser = macroParameterParser; _elementTypeCache = elementTypeCache; _richTextRequiredValidator = richTextRequiredValidator; + _richTextRegexValidator = richTextRegexValidator; _jsonSerializer = jsonSerializer; _logger = logger; @@ -257,6 +303,8 @@ public RichTextPropertyValueEditor( public override IValueRequiredValidator RequiredValidator => _richTextRequiredValidator; + public override IValueFormatValidator FormatValidator => _richTextRegexValidator; + /// public override object? Configuration { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/Validators/IRichTextRegexValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/Validators/IRichTextRegexValidator.cs new file mode 100644 index 000000000000..8b6955432215 --- /dev/null +++ b/src/Umbraco.Infrastructure/PropertyEditors/Validators/IRichTextRegexValidator.cs @@ -0,0 +1,5 @@ +namespace Umbraco.Cms.Core.PropertyEditors.Validators; + +internal interface IRichTextRegexValidator : IValueFormatValidator +{ +} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/Validators/RichTextRegexValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/Validators/RichTextRegexValidator.cs new file mode 100644 index 000000000000..aefbe3a5deaa --- /dev/null +++ b/src/Umbraco.Infrastructure/PropertyEditors/Validators/RichTextRegexValidator.cs @@ -0,0 +1,30 @@ +using System.ComponentModel.DataAnnotations; +using Microsoft.Extensions.Logging; +using Umbraco.Cms.Core.Serialization; +using Umbraco.Cms.Core.Services; + +namespace Umbraco.Cms.Core.PropertyEditors.Validators; + +internal class RichTextRegexValidator : IRichTextRegexValidator +{ + private readonly RegexValidator _regexValidator; + private readonly IJsonSerializer _jsonSerializer; + private readonly ILogger _logger; + + public RichTextRegexValidator( + IJsonSerializer jsonSerializer, + ILogger logger, + RegexValidator regexValidator) + { + _jsonSerializer = jsonSerializer; + _logger = logger; + _regexValidator = regexValidator; + } + + public IEnumerable ValidateFormat(object? value, string? valueType, string format) => _regexValidator.ValidateFormat(GetValue(value), valueType, format); + + private object? GetValue(object? value) => + RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue) + ? richTextEditorValue?.Markup + : value; +}