* Added a custom RichTextRequiredValidator, to check that the empty richtext object (still with json) can be required or not. We are now testing the markdown needs to have a value * Fixed namespaced and moved back wrong class * Cleanup
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
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 RichTextRequiredValidator : RequiredValidator, IRichTextRequiredValidator
|
|
{
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
private readonly ILogger<RichTextRequiredValidator> _logger;
|
|
|
|
public RichTextRequiredValidator(ILocalizedTextService textService, IJsonSerializer jsonSerializer, ILogger<RichTextRequiredValidator> logger) : base(textService)
|
|
{
|
|
_jsonSerializer = jsonSerializer;
|
|
_logger = logger;
|
|
}
|
|
|
|
public override IEnumerable<ValidationResult> ValidateRequired(object? value, string? valueType) => base.ValidateRequired(GetValue(value), valueType);
|
|
|
|
private object? GetValue(object? value)
|
|
{
|
|
if(RichTextPropertyEditorHelper.TryParseRichTextEditorValue(value, _jsonSerializer, _logger, out RichTextEditorValue? richTextEditorValue))
|
|
{
|
|
return richTextEditorValue?.Markup;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
}
|