Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Picker 3 relations not created from block list or nested content #80

Open
alanwthom opened this issue Dec 3, 2021 · 2 comments
Open

Comments

@alanwthom
Copy link

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 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.

@alanwthom
Copy link
Author

Hi @dawoe

Do you have any indication of when a fix for this could be expected please?

Thanks

@alanwthom
Copy link
Author

Hi @dawoe

Would it be possible to get an update on this please?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant