From 4fbdfd8484b4fef52c5664435ca648b7d5e5e695 Mon Sep 17 00:00:00 2001 From: Marc Goodson Date: Fri, 5 Apr 2024 09:47:27 +0100 Subject: [PATCH 1/2] Handle the 'sometimes' when the stored ContentBlock data appears as a JArray instead of a string In some circumstances eg when a ContentmentBlocks is nested inside the Core Umbraco BlockList (yes I know) and it's moved between environments (uSync/Cloud) then the ContentBlock content although 'transferred' successfully doesn't get rendered by the ContentBlocksValueConverter because of the check to see if it is a string. When Umbraco saves ContentBlocks within the BlockList JSON, then it escapes all the things \\\\\\ and when it's ready in the ConvertSourceToIntermediate it is interpreted as a string as it's no longer valid JArray... but when it's moved by a serialisation/deserialisation tool, then actually the stored value is a valid JArray and Umbraco returns the object to ConvertSourceToIntermediate as a JArray... ... which is why this PropertyValueConverter skips displaying it ... (but it loads the content fine in the backoffice) this pragmatic suggestion sort of caters for this quite niche scenario - but also I don't think does any harm to non-niche scenarios and is the place in the whole setup with the least moving parts, but also also, spiritually I recognise this probably isn't the internationally agreed place to fix this sort of thing... --- .../DataEditors/ContentBlocks/ContentBlocksValueConverter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs index 6f206e9d..2c446aa8 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs @@ -50,7 +50,10 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub { return JsonConvert.DeserializeObject>(value); } - + else if (source is JArray jValue) + { + return JsonConvert.DeserializeObject>(jValue.ToString()); + } return base.ConvertSourceToIntermediate(owner, propertyType, source, preview); } From d821498f68b9aad24a1da13784b49e739085297e Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 19 Apr 2024 09:22:41 +0100 Subject: [PATCH 2/2] Converts `JArray` object, to remove the `.ToString()` step --- .../ContentBlocks/ContentBlocksValueConverter.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs index 2c446aa8..759641ad 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Umbraco.Community.Contentment.Web.PublishedCache; #if NET472 using Umbraco.Core; @@ -50,10 +52,12 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub { return JsonConvert.DeserializeObject>(value); } - else if (source is JArray jValue) + + if (source is JArray array && array.Any() == true) { - return JsonConvert.DeserializeObject>(jValue.ToString()); + return array.ToObject>(); } + return base.ConvertSourceToIntermediate(owner, propertyType, source, preview); }