Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Issue 2934596 broke matching of media tags for me. I have blocks with tags like this:
[[{"type":"media","view_mode":"media_original","fid":"7","attributes":{"alt":"","class":"media-image","height":"148","typeof":"foaf:Image","width":"300"}}]]
which are not matched by the new regex because there are no characters between the { and the quote. Changing the regex to this:
define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[\{.*?"type":"media".+?\}\]\]/s');
fixes the problem.
I am using PHP Version 7.0.22-0ubuntu0.16.04.1.
Comment | File | Size | Author |
---|---|---|---|
#11 | media-recognition_of_media_tags-2942482-11.patch | 582 bytes | joseph.olstad |
|
Comments
Comment #2
joseph.olstadComment #3
joseph.olstadmentioned code will be reverted, publish 2.16 release with this revert.
Comment #4
joseph.olstadactually, I reviewed this again, the issue summary makes no sense because it says to put the same regex as already is in 2.15
very confused
also, I tested media_dev using 2.15 in simplytest.me and there were no issues with the regex that I could find.
I will run some more tests on a site with 2.14 with some test data and try upgrading to 2.15 and see what happens.
Comment #5
joseph.olstadIf this is indeed still an issue, could you make a patch? it'd be easier to review to see the before and after.
Comment #6
joseph.olstadhere's a test I ran
https://dcg8.ply.st/node/1
link is good from now until 12 hours from now.
Comment #7
adriancotter CreditAttribution: adriancotter commentedThis is an issue for me...
One important note -- it only seems happens in blocks. Media content in nodes seems fine as far as I have been able to find.
EDIT --> this might just be the fact that the content in blocks is older and was still using some older syntax?!
The media item does also appears fine in the WYSIWYG, it is just not getting rendered on the front end. I tried adding spaces in the media notation but that did not help matters.
This is an example of one that is inside a BLOCK and is NOT working. This was a PREEXISTING media item
If I add a new one, it appears as the one working below...
[[{"type":"media","view_mode":"media_large","fid":"2397","link_text":null,"field_deltas":{"1":{}},"fields":{},"attributes":{"style":"width: 500px; height: 63px;","class":"media-image media-element file-media-large","id":"styles-0-0","data-delta":"1"}}]]
This is a one that inside a NODE and is working :
[[{"fid":"3321","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false,"field_photographer[und][0][value]":"","field_caption[und][0][value]":"","field_permissions[und][0][value]":""},"link_text":null,"type":"media","field_deltas":{"1":{"format":"default","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false,"field_photographer[und][0][value]":"","field_caption[und][0][value]":"","field_permissions[und][0][value]":""}},"attributes":{"class":"media-element file-default","data-delta":"1"}}]]
I was able to fix by just re-picking the image for the various effected blocks -- but it would nice if the old images were rendered as well -- I'm sure I missed some. If i have time tomorrow, I'll try and dig out the REGEX and have a look.
Comment #8
koosvdkolk CreditAttribution: koosvdkolk commentedThe latest update breaks all our media tags, everywhere :-(
Comment #9
alrh CreditAttribution: alrh commentedThe suggested change in the regex is: replacing the first .+? with .*? (matching 0 or more characters between [[{ and "type":"media" instead of 1 or more).
Comment #10
hcethatsme CreditAttribution: hcethatsme commentedBreaks all our media tags too, for the same reason: they start [[{"type":"media". When I insert a space between [[{ and "type", bingo, it's fine. alrh's fix works for us!
Comment #11
joseph.olstadwould be faster if someone had made a patch the first time.
here's a patch as discussed above.
Comment #14
joseph.olstadComment #15
joseph.olstadI wouldn't be surprised to hear about more people complaining about the latest regex regression fix.
I hesitated to change this regex in the first place. It was working well enough before but the related issue came up and I thought ya maybe it'd be good to support the edge case too but ya, got bit again by this.
Comment #16
joseph.olstadanyhow, new release , 2.16 with the patch 11
also 3.0-rc2
Comment #17
MartinTomes CreditAttribution: MartinTomes commentedThanks for putting this fix in.
Comment #18
koosvdkolk CreditAttribution: koosvdkolk commentedThanks a lot indeed, Joseph!
Comment #19
joseph.olstadHopefully this latest change holds up well in the real world. Thanks everyone for the timely responses.
Media keeps getting better and better
Comment #21
weseze CreditAttribution: weseze at Sandra Wesley CommV commentedI have experienced a site with the following token:
It doesn't get replaced because it contains "type":"media"}]] at the very end and that does not match the regex:
If I replace the regex with:
It does get replaced.
Any thoughts?
I can work arround this issue by just resaving all nodes that contain these tokens, but in an automated update flow this does not work :)
Comment #22
joseph.olstadThanks for your detailed report and analysis.
needs review, perhaps @kaare could weigh in on this?
The regex has been adjusted quite a few times to accomodate various configurations and support various configurations of other contrib modules. It looks like there's an opportunity for improvement here.
This very small change proposed may be appropriate however it needs some review.
@weseze is proposing changing this:
to this:
Comment #23
joseph.olstadComment #24
joseph.olstadduplicate issue:
see: #2976467: Unable to render media tokens after upgrading to 7.x-2.19
Comment #25
joseph.olstadsee these commits in dev
fixed in 2.x / 3.x and 4.x dev branches
Issue #2942482 AND Issue #2976467 by shivamitakari, MartinTomes, koosvdkolk, .
https://cgit.drupalcode.org/media/commit/?h=7.x-3.x&id=412234c749d65d9e6...
and
https://cgit.drupalcode.org/media/commit/?h=7.x-4.x&id=ad9e3b55066be4fa8...
If all goes well and no reported regressions then this change will make it into the next release of Media 7.x-2.x / 7.x-3.x and 7.x-4.x