I've got a problem with Media module for Drupal 7, it works great all over the site, except in a custom module I've created. The field that is used by this module, uses the same text formatting as rest of site, it properly renders bolds, tables, all TinyMCE things. But somehow it can't handle images inserted by media plugin.
If I add ordinary article content type, then it works ok. Only fields rendered by my module are not parsed.
So - I display a field by:
开发者_如何学运维 echo '<p class="product-section-content">' . $element['value'] . '</p>'."\n";
but, instead of image I get:
[[{"type":"media","view_mode":"media_large","fid":"71","attributes":{"alt":"","class":"media-image","typeof":"foaf:Image"}}]][[{"type":"media","view_mode":"media_large","fid":"63","attributes":{"alt":"","class":"media-image","typeof":"foaf:Image"}}]]
What should I call, to parse this markup tags?
It's because the Media module provides a new input filter that's not activated by default. This filter is required to parse the media tags.
You need to go to admin/config/content/formats
, edit the text format(s) you want to use with media, and enable the Converts Media tags to Markup
checkbox for each.
Then it'll work :)
For Media module (1.x branch only) you can normally use the media_filter function:
print media_filter(html);
If any one use Media module 2.x branch, you should use:
print media_wysiwyg_filter(html);
Looks like you need to use the render() function rather than just printing out the value for an element.
http://api.drupal.org/api/drupal/includes--common.inc/function/render/7
so your code should look more like this:
echo '<p class="product-section-content">'.render($element).'</p>'."/n";
Would help to have a little bit more context about your module. Are you trying to print out this element in a template file? Is your goal just to edit the wrapping HTML for the element? etc.
Hey You need to use the drupal "safe_value" instead of "value"
精彩评论