Created
June 28, 2012 16:05
-
-
Save davereid/3012194 to your computer and use it in GitHub Desktop.
Workaround for embedding non-image media in WYSIWYG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_media_token_to_markup_alter(). | |
* | |
* Allow non-image files to be embedded in the WYSIWYG by converting the | |
* 'preview' markup to be shown in the WYSIWYG to an image preview of the file. | |
*/ | |
function custom_media_token_to_markup_alter(&$element, $tag_info, $settings) { | |
if (!empty($settings['wysiwyg']) && $tag_info['file']->type != 'image') { | |
$element = media_get_file_without_label($tag_info['file'], 'media_preview', $settings); | |
} | |
} | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
* | |
* Alter the media embed form to show to the user that the file will only be | |
* shown in the WYSIWYG as a preview and not the actual file contents. | |
*/ | |
function custom_form_media_format_form_alter(&$form) { | |
if (!empty($form['#media']->override['wysiwyg'])) { | |
foreach ($form['#formats'] as $view_mode => $preview) { | |
$element = media_get_file_without_label($form['#media'], 'media_preview'); | |
$form['#formats'][$view_mode] = drupal_render($element); | |
} | |
$form['heading']['#suffix'] .= '<div class="messages warning">' . t('This media will be shown as a preview in the WYSIWYG since it is not an image.') . '</div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment