From 4294b5a078702cb0e4510d5987b12290a9b35948 Mon Sep 17 00:00:00 2001 From: Lucas Bach Bisgaard Date: Tue, 9 Sep 2025 16:23:49 +0200 Subject: [PATCH] Resolve composition properties on a block for the RTE. (#20105) * dont rellay on only resolved based on properties, but also scan the CompositionPropertyTypes to resolve compistion inside the black * Refactored to helper method. --------- Co-authored-by: Lucas Bach Bisgaard Co-authored-by: Andy Butland --- .../RichTextEditorValueExtensions.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/Extensions/RichTextEditorValueExtensions.cs b/src/Umbraco.Infrastructure/Extensions/RichTextEditorValueExtensions.cs index 3cc16b6c21..3a456bb8a8 100644 --- a/src/Umbraco.Infrastructure/Extensions/RichTextEditorValueExtensions.cs +++ b/src/Umbraco.Infrastructure/Extensions/RichTextEditorValueExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache.PropertyEditors; using Umbraco.Cms.Core.Models; @@ -31,8 +32,30 @@ internal static class RichTextEditorValueExtensions { foreach (BlockPropertyValue item in dataItem.Values) { - item.PropertyType = elementTypes.FirstOrDefault(x => x.Key == dataItem.ContentTypeKey)?.PropertyTypes.FirstOrDefault(pt => pt.Alias == item.Alias); + if (TryResolvePropertyType(elementTypes, dataItem.ContentTypeKey, item.Alias, out IPropertyType? resolvedPropertyType)) + { + item.PropertyType = resolvedPropertyType; + } } } } + + private static bool TryResolvePropertyType(IEnumerable elementTypes, Guid contentTypeKey, string propertyTypeAlias, [NotNullWhen(true)] out IPropertyType? propertyType) + { + IContentType? elementType = elementTypes.FirstOrDefault(x => x.Key == contentTypeKey); + if (elementType is null) + { + propertyType = null; + return false; + } + + propertyType = elementType.PropertyTypes.FirstOrDefault(pt => pt.Alias == propertyTypeAlias); + if (propertyType is not null) + { + return true; + } + + propertyType = elementType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias); + return propertyType is not null; + } }