drupal 7 hook_node_view将一个表单添加到节点的内容 [英] Drupal 7 hook_node_view add a form to the content of a node

查看:85
本文介绍了drupal 7 hook_node_view将一个表单添加到节点的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function example_module_node_view($node, $view_mode, $langcode)
{   
    $f =  drupal_get_form('example_module_form', $node);
    $node->content['data_collection_form'] = array('#value' => $f, '#weight' => 1); 
}

为什么窗体不显示?我做错了吗?正在填充表单对象。我可以做#markup =>'Something',它的作品。

Why doesn't the form display? Am I doing something wrong? The form object is being populated. I can do #markup => 'Something' and it works.

推荐答案

drupal_get_form 实际上是一个渲染数组本身,所以你可以这样做:

The return from drupal_get_form is actually a render array itself so you could just do this:

$f = drupal_get_form('example_module_form', $node);
$f['#weight'] = 1;
$node->content['data_collection_form'] = $f;

如果你想做另一种方式,虽然表单应该是可渲染的元素所以关键不应该以为前缀:

If you do want to do it the other way though the form should be a renderable 'element', so the key shouldn't be prefixed by #:

$f = drupal_get_form('example_module_form', $node);
$node->content['data_collection_form'] = array(0 => $f, '#weight' => 1);

具有前缀为被认为是属性,而那些不被认为是孩子并被递归呈现。

All entries in a render array with a key prefixed with # are considered properties, while those that aren't are considered 'children' and are recursively rendered.

这篇关于drupal 7 hook_node_view将一个表单添加到节点的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆