With the hook_media_format_form_prepare_alter() I can modify the form in the embedding process. But I have no possibility to change the inserted html/media markup. Because in the "Options" step where I select the Display and fill out the altered options form, the inserted html for the editor is already generated in Drupal.settings.media.formatFormFormats.
Example:
I have altered the options form in the Embedding process for documents, to enter a custom text for the link (see attached screenshot). But I have not found a simple way, so that the value of my field change the inserted html.
Only via hook_media_token_to_markup_alter(). But that hook only is used for the "final output". So the display of the media integration in the WYSIWYG editor and the final html output on the site can be very different.
But for the editor it is quite illogical if the document link is inserted in the editor with the filename and on the website it is rendered with the entered link text.
Proposed solution:
Don't generate the inserted html in the second step. We can send a AJAX request after the options step, that generate, render and return the html for the media item. In this process we can also implement an alter hook (similarly to hook_media_token_to_markup_alter()), so that modules can affect the inserted html (for example to process the additional input from the "Options" step).
Comments
Comment #1
cbeier CreditAttribution: cbeier commentedComment #2
das-peter CreditAttribution: das-peter at Cando commentedJust ran into a similar issue. It is indeed a bit odd that we can adjust the markup to display in the WYSIWYG Editor when loading existing content but are unable to define what markup to display when selecting a new file.
I suggest we introduce an alter hook for
media_wysiwyg_get_file_without_label()
which is used in both locationsmedia_wysiwyg_format_form()
andmedia_wysiwyg_token_to_markup()
.Comment #3
euk CreditAttribution: euk at WebFirst, Inc. commentedAdding just a slightly improved patch version which we have been using pretty well.