diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs index b28a99472b..31cabac3bf 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs @@ -270,21 +270,20 @@ public class RichTextPropertyEditor : DataEditor internal override object? MergePartialPropertyValueForCulture(object? sourceValue, object? targetValue, string? culture) { - if (sourceValue is null) + if (sourceValue is null || TryParseEditorValue(sourceValue, out RichTextEditorValue? sourceRichTextEditorValue) is false) { return null; } - if (TryParseEditorValue(sourceValue, out RichTextEditorValue? sourceRichTextEditorValue) is false - || sourceRichTextEditorValue.Blocks is null) + if (sourceRichTextEditorValue.Blocks is null) { - return null; + return sourceValue; } BlockEditorData? sourceBlockEditorData = ConvertAndClean(sourceRichTextEditorValue.Blocks); if (sourceBlockEditorData?.Layout is null) { - return null; + return sourceValue; } TryParseEditorValue(targetValue, out RichTextEditorValue? targetRichTextEditorValue); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/PropertyEditors/RichTextElementLevelVariationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/PropertyEditors/RichTextElementLevelVariationTests.cs index 934ceea083..ad40548aac 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/PropertyEditors/RichTextElementLevelVariationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/PropertyEditors/RichTextElementLevelVariationTests.cs @@ -6,6 +6,7 @@ using Umbraco.Cms.Core.Models.DeliveryApi; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Tests.Common.Builders; +using Umbraco.Cms.Tests.Common.Builders.Extensions; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.PropertyEditors; @@ -363,6 +364,64 @@ public class RichTextElementLevelVariationTests : BlockEditorElementVariationTes } } + [Test] + public async Task Can_Publish_Without_Blocks_Variant() + { + var elementType = CreateElementType(ContentVariation.Culture); + + var blockGridDataType = await CreateRichTextDataType(elementType); + var contentType = CreateContentType(blockGridDataType); + var richTextValue = new RichTextEditorValue { Markup = "

Markup here

", Blocks = null }; + var content = CreateContent(contentType, richTextValue); + + PublishContent(content, ["en-US", "da-DK"]); + + AssertPropertyValues("en-US"); + AssertPropertyValues("da-DK"); + + void AssertPropertyValues(string culture) + { + SetVariationContext(culture, null); + var publishedContent = GetPublishedContent(content.Key); + var property = publishedContent.GetProperty("blocks"); + Assert.IsNotNull(property); + + var propertyValue = property.GetDeliveryApiValue(false, culture) as RichTextModel; + Assert.IsNotNull(propertyValue); + Assert.AreEqual("

Markup here

", propertyValue.Markup); + Assert.IsEmpty(propertyValue.Blocks); + } + } + + [Test] + public async Task Can_Publish_Without_Blocks_Invariant() + { + var elementType = CreateElementType(ContentVariation.Culture); + + var blockGridDataType = await CreateRichTextDataType(elementType); + var contentType = CreateContentType(ContentVariation.Nothing, blockGridDataType); + var richTextValue = new RichTextEditorValue { Markup = "

Markup here

", Blocks = null }; + var content = CreateContent(contentType, richTextValue); + + PublishContent(content, ["*"]); + + AssertPropertyValues("en-US"); + AssertPropertyValues("da-DK"); + + void AssertPropertyValues(string culture) + { + SetVariationContext(culture, null); + var publishedContent = GetPublishedContent(content.Key); + var property = publishedContent.GetProperty("blocks"); + Assert.IsNotNull(property); + + var propertyValue = property.GetDeliveryApiValue(false, culture) as RichTextModel; + Assert.IsNotNull(propertyValue); + Assert.AreEqual("

Markup here

", propertyValue.Markup); + Assert.IsEmpty(propertyValue.Blocks); + } + } + private async Task CreateRichTextDataType(IContentType elementType) => await CreateBlockEditorDataType( Constants.PropertyEditors.Aliases.RichText, @@ -480,9 +539,18 @@ public class RichTextElementLevelVariationTests : BlockEditorElementVariationTes private IContent CreateContent(IContentType contentType, RichTextEditorValue richTextValue) { var contentBuilder = new ContentBuilder() - .WithContentType(contentType) - .WithCultureName("en-US", "Home (en)") - .WithCultureName("da-DK", "Home (da)"); + .WithContentType(contentType); + + if (contentType.VariesByCulture()) + { + contentBuilder + .WithCultureName("en-US", "Home (en)") + .WithCultureName("da-DK", "Home (da)"); + } + else + { + contentBuilder.WithName("Home"); + } var content = contentBuilder.Build();