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

firewaller created an issue. See original summary.

firewaller’s picture

Here is an updated regex pattern I've been using (line 63 no longer overriden):

line 50: $pattern = '/\[\[(?<tag_info>{(.*?)("type":"media")?(.*?)})\]\]/s';
line 63: $tag_info = $decoder->decode($matches['tag_info'], JsonEncoder::FORMAT);

However, the same limitation as above exists since '"type":"media"' is not required.

huzooka’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce, +Needs tests

Hi @firewaller,

Could you please share an example JSON that shoudn't be parsed by Media Migration's WYSIWYG plugin?

firewaller’s picture

@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

huzooka’s picture

Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce

@firewaller, thank you!

For safety's sake, the string that fails:

[[nid:1234]]

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam finibus elit nec ipsum feugiat convallis. Aliquam tellus nisi, pretium viverra tortor id, tempor rutrum dui.

[[{"fid":"1234","view_mode":"default","type":"media"}]]

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam finibus elit nec ipsum feugiat convallis. Aliquam tellus nisi, pretium viverra tortor id, tempor rutrum dui.

[[{"fid":"1234","view_mode":"default","type":"media"}]]

[[nid:1234]]
huzooka’s picture

huzooka’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
huzooka’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

  • huzooka committed 1623129 on 8.x-1.x
    Issue #3096087 by huzooka, firewaller: Media WYSIWYG token matching...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.