Problem/Motivation
In 7.x-2.x, the markup that gets rendered into WYSIWYG is "pre-built" in a JS settings array (Drupal.settings.media.formatFormFormats) and attached when the modal popup is launched. This is a problem if one wants to dynamically change the markup based on options and fields added in the popup.
Use case: There is an alignment field (right, left, center).
Proposed resolution
Rather than pre-computing the markup and attaching, dynamically build the markup using a new hook_menu callback. This menu provides the same markup as currently provided by the existing JS solution. But there is a drupal_alter hook available to enhance the markup that gets rendered.
Remaining tasks
Reviews
User interface changes
n/a
API changes
Change: Markup is generated dynamically after submitting the Media WYSIWYG modal form. Changes to formats using media_wysiwyg_format_form_prepare will no longer effect the rendered markup in the WYSIWYG. It will only effect the markup in the modal popup.
Addition: There is a new alter hook (hook_media_wysiwyg_wysiwyg_markup_alter) that provides a mechanism to enhance and/or replace the default markup that gets rendered in WYSIWYG.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | media-allow_dynamic_wysiwyg_markup-2348439-6-db_table_exists.patch | 9.87 KB | zuernbernhard |
| #6 | media-allow_dynamic_wysiwyg_markup-2348439-6-do-not-test.patch | 9.7 KB | heddn |
| #5 | media-allow_dynamic_wysiwyg_markup-2348439-5.patch | 9.53 KB | heddn |
| #5 | interdiff_4-5.txt | 895 bytes | heddn |
Comments
Comment #1
heddnLet's see how things fair with the testbot. There was a large amount of what seemed like crufty/old js in popup.js. Rather than fix it to use a js callback for the ajax calls, I opted to remove it.
Comment #2
heddnAdded api.php docs.
Comment #3
heddnFollowing the lead in #2349977: DoS image derivatives in Media WYSIWYG, I've updated the hook_menu to use a more restrictive security access callback.
Additionally, if you happen to run #1792738: Allow custom file view modes for WYSIWYG display, then you'll want to apply the do-not-test patch.
Comment #4
heddnUpdates to follow the lead in #2349977: DoS image derivatives in Media WYSIWYG.
Comment #5
heddnContinuing to follow the lead in #2349977-8: DoS image derivatives in Media WYSIWYG
Comment #6
heddnThe do-not-test patch is the same as test. This fixes that.
Comment #7
zuernbernhard commentedGreat Work !!!
One Thing: i have no table "media_view_mode_wysiwyg" and thats why i get an exception in media_wysiwyg_wysiwyg_markup.
patched patch (just added "if (db_table_exists('{media_view_mode_wysiwyg}')) {" )is attached.
What is still missing to see this in the module ?
Comment #9
zuernbernhard commentedBTW.: We use this together with Media Browser Plus (https://www.drupal.org/project/media_browser_plus) and Entity Emed Backport (https://www.drupal.org/sandbox/brockfanning/2400183) to Insert Images as Entities Using CKEditor Widgets.
Our Editors are happy to have these Widgets and with Filebrowser (https://www.drupal.org/project/filebrowser) they can rearrange the Images in the filesystem without "breaking" the already inserted images instances.
Comment #12
devin carlson commentedComment #13
chiebert commentedThe do-not-test patch in #6 (which supposed to apply if you're using #1792738: Allow custom file view modes for WYSIWYG display) fails on two hunks (if you've applied the latest from that issue against the latest -dev) as follows:
On looking at the two failed hunks, the hook_permission() change had already been applied, but I needed to manually add the following to hook_menu() in media_wysiwyg.module:
And without this patch, the patch in #1792738: Allow custom file view modes for WYSIWYG display wouldn't save overrides to the embedded media on form submit.
Comment #14
chiebert commentedSame with the patch in #5 (didn't try #7 since it was failing tests, but I guess it would be the same for that as well): the permission change is now already in -dev, so these need a re-roll. Never done one of those before...
Comment #15
kevinquillen commentedWould seem to cause the issue of it not respecting a media object used more than once in a WYSIWYG field. If you use the same image multiple times with different view modes, it does not distinguish between any of them and simply replaces all tokens matching on very basic patterns. This overwrites the selected view mode on the tokens, causing all instances of the same image inserted to use that view mode. It needs to respect the view mode selected per token.
Also media source map in Drupal.settings doesn't record anything but the file and fid, making it difficult to reuse the same file multiple ways.
Comment #16
joseph.olstadsee parent issue:
support for float media left and float media right
this functionality was added a while back, and works quite well