Drupal 7 hook_node_view add a form to the content of a node(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 添加表单到节点的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Drupal 7 hook_node_view 添加表单到节点的内容


- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01