Drupal - 自定义主题不解析媒体模块标记
我在 Drupal 7 的媒体模块上遇到了问题,除了我创建的自定义模块之外,它在整个网站上都运行良好。 该模块使用的字段使用与站点其余部分相同的文本格式,它可以正确呈现粗体、表格和所有 TinyMCE 内容。但不知何故它无法处理媒体插件插入的图像。
如果我添加普通文章内容类型,那么它就可以正常工作。只有我的模块呈现的字段不会被解析。
所以 - 我通过以下方式显示一个字段:
echo '<p class="product-section-content">' . $element['value'] . '</p>'."\n";
但是,我得到的不是图像:
[[{"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"}}]]
我应该调用什么来解析此标记?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是因为媒体模块提供了一个新的输入过滤器,默认情况下未激活。需要此过滤器来解析媒体标签。
您需要转到
admin/config/content/formats
,编辑要用于媒体的文本格式,然后启用将媒体标记转换为标记
复选框对于每个。然后就可以工作了:)
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 theConverts Media tags to Markup
checkbox for each.Then it'll work :)
对于 Media 模块(仅限 1.x 分支),您通常可以使用 media_filter功能:
For Media module (1.x branch only) you can normally use the media_filter function:
如果有人使用 Media module 2.x 分支,您应该使用:
If any one use Media module 2.x branch, you should use:
看起来您需要使用 render() 函数,而不仅仅是打印出元素的值。
http://api.drupal.org/api/ drupal/includes--common.inc/function/render/7
因此您的代码应该看起来更像这样:
有助于了解有关您的模块的更多上下文。您是否尝试在模板文件中打印此元素?您的目标只是编辑元素的包装 HTML 吗? ETC。
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:
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.
嘿,你需要使用 drupal“safe_value”而不是“value”
Hey You need to use the drupal "safe_value" instead of "value"