When running a standard D7 to D8 node migration with media_wysiwyg tokens and other contrib/custom tokens, the REGEX pattern matching conflicts, breaks the migrated content, and results in the following warning:
[warning] Message: The following media_wysiwyg token in node NODE_ID does not have valid JSON: ...
After digging into this, it seems like the media_wysiwyg_filter plugin regex is not specific enough in \Drupal\media_migration\Plugin\migrate\process\MediaWysiwygFilter::transform
An approach I've used successfully is to check for the media_wysiwyg JSON brackets within the tokens in the REGEX and adding the JSON brackets back in the decode function:
Before:
line 50: $pattern = '/\[\[(?<tag_info>.+?"type":"media".+?)\]\]/s';
line 63: $tag_info = $decoder->decode($matches['tag_info'], JsonEncoder::FORMAT);After:
line 50: $pattern = '/\[\[\{(?<tag_info>.+?"type":"media".+?)\}\]\]/s';
line 63: $tag_info = $decoder->decode('{' . $matches['tag_info'] . '}', JsonEncoder::FORMAT);However, this workaround will still conflict with any contrib/custom tokens using JSON, so a more thorough solution is required.
Comments
Comment #2
firewaller commentedHere is an updated regex pattern I've been using (line 63 no longer overriden):
However, the same limitation as above exists since '"type":"media"' is not required.
Comment #3
huzookaHi @firewaller,
Could you please share an example JSON that shoudn't be parsed by Media Migration's WYSIWYG plugin?
Comment #4
firewaller commented@huzooka The Node Embed contrib module uses the token format [[nid:1234]] that conflicts with the REGEX and causes the above issue.
Here is an example: https://regex101.com/r/22dy3e/1
Comment #5
huzooka@firewaller, thank you!
For safety's sake, the string that fails:
Comment #6
huzookaComment #8
huzookaComment #9
huzooka