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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cbeier’s picture

Component: Code » Media Browser
das-peter’s picture

Just 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 locations media_wysiwyg_format_form() and media_wysiwyg_token_to_markup().

euk’s picture

Adding just a slightly improved patch version which we have been using pretty well.