Problem/Motivation

When a Media token is used inside a Markdown link, media_wysiwyg_filter_parse_from_fields() fails to correctly parse the JSON in a Media tag.

For example, here's a Markdown link:
[Click here to see what happens next!](/click-bait)

If a Media token is inside the link, the syntax is:
[[[{"type":"media","view_mode":"default","fid":"12345","attributes":{"class":"","typeof":"foaf:Image","style":""}}]]](/click-bait)

When media_wysiwyg_filter_parse_from_fields() detects the Media tag, it only strips two of the three opening square brackets. Because it leaves one opening square bracket, the call to drupal_json_decode() fails.

This does not affect rendering of Media entity, as that works fine if input filters ordered correctly (Markdown filter before Media).

Proposed resolution

Attached patch strips three opening square brackets, in addition to strings it currently strips.

Remaining tasks

If existing Media tokens use this syntax, I don't know how to force media_wysiwyg to count a file as used. This is because media_wysiwyg_filter_parse_from_fields() compares the number of files on $entity->original vs $entity, but that number will always be the same, because the triple opening bracket will be stripped for both.

User interface changes

n/a

API changes

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

krisahil’s picture

Chris Matthews’s picture

Status: Active » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team