Overriding theme_link on wysiwyg embedded images

cato's picture

Using the latest dev of Media on D7.25, I'm having a small issue when embedding images that are linked through the view mode.

I try to override theme_link to add a FID attribute to the links but this does not work unless I flush the cache manually. I can't seem to find any clues as to where in Media or media_wysiwyg the links get generated initially or if this is a cache issue.

On the site we have disabled all caching during development so it's kinda weird we have to flush the cache at all.

Now, question is, should I be overriding some other hook or should the theme_link override really be working here? I'm guessing this might be due to something with the media_token_to_markup function but that function doesn't seem to run when I expect it to run - i.e. on either node insert / update or node view.


Where are you implementing

arthurf's picture

Where are you implementing hook_media_token_to_markup_alter() ?

@arthurf there was a small

cato's picture

@arthurf there was a small typo in my code as well as in the post. It's media_wysiwyg_token_to_markup_alter() and after I fixed the typo I can actually see that it's executed as it should. It's implemented in our custom module where we do all overrides for the site.

Since it's actually working now thanks to my now typo-free code I'll start looking around for which of $settings, $tag_info and $element has the link in it. I'll update this post when I make some progress.

Solved it

cato's picture

That's what you get for making typos and not reading source code properly...

To get the fid attribute on the links I added the following override function in a custom module:

function MYMODULE_media_wysiwyg_token_to_markup_alter(&$element, $tag_info, $settings)
    $element['content']['file']['#path']['options']['attributes']['fid'] = $element['content']['file']['#item']['fid'];

This could also be used to add accessibility options on the links such as titles and other goodies.


Group organizers

Group categories

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week