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.
I'm having trouble with the following code in media_wysiwyg.filter.js:
// Re-build the macros in case any element has changed in the editor.
$('.media-element', content).each(function(i, element) {
var markup = Drupal.media.filter.outerHTML($(element));
macro = Drupal.media.filter.create_macro($(element));
// Store the macro => html for more efficient rendering in
// replaceTokenWithPlaceholder().
Drupal.settings.tagmap[macro] = markup;
// Replace the media element with its macro.
content = content.replace(markup, macro);
});
It's not replacing the placeholder with the media tag because the markup variable isn't identical to the html in the original content. For example I can add a single placeholder for a video as an image preview and the markup variable will be:
<img alt="ug0ifwslG84" class="media-element file-full" data-file_info="%7B%22fid%22:%2224384%22,%22view_mode%22:%22full%22,%22fields%22:%7B%22format%22:%22full%22,%22field_video_caption%5Bund%5D%5B0%5D%5Bvalue%5D%22:%22%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_energy%5D%22:%220%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_timestamp%5D%22:%221396445177%22%7D,%22type%22:%22media%22%7D" src="http://localhost:90/sites/default/files/styles/wide_medium/public/media-youtube/ug0ifwslG84.jpg?itok=Jl98_8QZ" typeof="foaf:Image" height="169" width="300">
But the content variable will be:
<p><img alt="ug0ifwslG84" class="media-element file-full" data-file_info="%7B%22fid%22:%2224384%22,%22view_mode%22:%22full%22,%22fields%22:%7B%22format%22:%22full%22,%22field_video_caption%5Bund%5D%5B0%5D%5Bvalue%5D%22:%22%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_energy%5D%22:%220%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_timestamp%5D%22:%221396445177%22%7D,%22type%22:%22media%22%7D" height="169" src="http://localhost:90/sites/default/files/styles/wide_medium/public/media-youtube/ug0ifwslG84.jpg?itok=Jl98_8QZ" typeof="foaf:Image" width="300"></p>
Note the placement of the height attribute in each. The html is equivalent but it doesn't match when replace is called.
Comment | File | Size | Author |
---|---|---|---|
#3 | media_wysiwyg-fix_placeholders-2231463-3.patch | 1.27 KB | jmuzz |
Comments
Comment #1
jmuzz CreditAttribution: jmuzz commentedHere's a fix that works by converting content into a jQuery object and using jQuery's replaceWith function.
Comment #2
jmuzz CreditAttribution: jmuzz commentedThat solution caused errors when the content was empty.
Comment #3
jmuzz CreditAttribution: jmuzz commentedFixed a bug described at https://drupal.org/node/2236115 .
Comment #4
drclaw CreditAttribution: drclaw commentedI believe the issue you're experiencing will be fixed by #2126755: Improve Media's WYSIWYG Macro handling
I'm not familiar enough with this to judge whether or not this is a duplicate, however.
Comment #5
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedClosing 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