You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've installed Nexu into an existing installation. It's successfully picking up media relations where the property exists against directly a content type, but not when the property exists against an element type that is used in the block list editor or nested content.
Having looked through the codebase at how Umbraco models the Media Picker 3 data, it appears that previous versions of the media picker have data stored as umb://media/2fcfdeaa0e954ce4a6454d6d5b2d36f7 which is handled by a utility used by the BaseTextParser, but that the new Media Picker 3 stores a JSON object containing a "mediaKey" which points to the image (e.g. [{ "key": "b5190d63-153f-4df3-b1cd-3b3c3f243e90", "mediaKey": "2fcfdeaa-0e95-4ce4-a645-4d6d5b2d36f7", "crops": [], "focalPoint": { "left": 0.5, "top": 0.5 } }]). Therefore, when the existing GetMediaUdiFromText() method is run on a property editor value that uses the BaseTextParser (which includes Block lists and Nested content), any properties using the Media Picker 3 property are missed due to the new way their data is stored.
Using the MediaPicker3 parser as an example, I tried to have a whack at this myself, something like the following, however it seemed like Umbraco's method of storing this data with the JSON array stored as a string caused issues when trying to parse this as an array.
public static IEnumerable<Udi> GetMediaKeyFromText(string text)
{
var udiList = new List<Udi>();
var array = JArray.Parse(text);
if (array != null && array.Any())
{
var tokens = array.SelectTokens("$..*[?(@.mediaKey)].mediaKey");
udiList.AddRange(tokens?.Select(x => new StringUdi("media", x.ToString().Replace("-", ""))));
}
return udiList.DistinctBy(x => x.ToString());
}
Having then spend a while bashing my head against this, I can't see anyway to do this reliably (considering that Nested content will be an array and Block list content an object) without using a Regex expression. I think there may be a way to match on the "mediaKey" and then lookahead to the Guid value, however I've currently done this by taking the key and value via a regex expression then using .Substring() to get the value only. This does probably need corrected.
I've also updated the NestedContentParserTests to included an example of an Umbraco.MediaPicker3 input with nested content and added a BlockListContentParserTests file to include an example of an Umbraco.MediaPicker3 input with the block list editor.
The text was updated successfully, but these errors were encountered:
Nexu version: 2.3.0
Umbraco version: 8.14.0
I've installed Nexu into an existing installation. It's successfully picking up media relations where the property exists against directly a content type, but not when the property exists against an element type that is used in the block list editor or nested content.
Having looked through the codebase at how Umbraco models the Media Picker 3 data, it appears that previous versions of the media picker have data stored as
umb://media/2fcfdeaa0e954ce4a6454d6d5b2d36f7
which is handled by a utility used by the BaseTextParser, but that the new Media Picker 3 stores a JSON object containing a "mediaKey" which points to the image (e.g.[{ "key": "b5190d63-153f-4df3-b1cd-3b3c3f243e90", "mediaKey": "2fcfdeaa-0e95-4ce4-a645-4d6d5b2d36f7", "crops": [], "focalPoint": { "left": 0.5, "top": 0.5 } }]
). Therefore, when the existingGetMediaUdiFromText()
method is run on a property editor value that uses theBaseTextParser
(which includes Block lists and Nested content), any properties using the Media Picker 3 property are missed due to the new way their data is stored.Using the MediaPicker3 parser as an example, I tried to have a whack at this myself, something like the following, however it seemed like Umbraco's method of storing this data with the JSON array stored as a string caused issues when trying to parse this as an array.
Having then spend a while bashing my head against this, I can't see anyway to do this reliably (considering that Nested content will be an array and Block list content an object) without using a Regex expression. I think there may be a way to match on the "mediaKey" and then lookahead to the Guid value, however I've currently done this by taking the key and value via a regex expression then using
.Substring()
to get the value only. This does probably need corrected.I've also updated the
NestedContentParserTests
to included an example of anUmbraco.MediaPicker3
input with nested content and added aBlockListContentParserTests
file to include an example of anUmbraco.MediaPicker3
input with the block list editor.The text was updated successfully, but these errors were encountered: