I am using media module and using it in WYSIWYG. Is it possible to customize the display of media image? Is there any template file I can rewrite or any hook to call? I found file_entity.tpl.php. but it doesn't seem the correct one. Please suggest.



Credit for most of this answer to this article: http://forumone.com/insights/styling-inline-images-with-drupals-wysiwyg-and-media-modules/ First I went and edited the relevant displays and added a caption field (which is what I was trying to do)

Then used hook_media_wysiwyg_token_to_markup_alter() to change the output, in my case I needed to catch the situation where the image got floated in the WYSIWYG, and float the parent element rather.

function MODULENAME_media_wysiwyg_token_to_markup_alter(&$element, $tag_info, $settings) {
    if (($element['content']['#bundle'] == 'image')) {
        // check if a caption has been set
            if(isset($element['content']['file']['#attributes']['style']) && strstr($element['content']['file']['#attributes']['style'], 'float')){
                // move floats to the wrapping element
                $element['content']['#attributes']['style'] = $element['content']['file']['#attributes']['style'];
                // remove inline style on image
                $element['content']['file']['#item']['attributes']['style'] = '';
                // add class to wrapping element so we can style it
                $element['content']['#attributes']['class'][] = 'media-with-caption';
  • the link doesn't work anymore :-/ – commonpike Jun 8 '17 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.