Chr*_*nch 8 php drupal drupal-7
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);
}
Run Code Online (Sandbox Code Playgroud)
为什么表格不显示?难道我做错了什么?正在填充表单对象.我可以做#markup =>'Something'并且它有效.
返回drupal_get_form实际上是一个渲染数组本身,所以你可以这样做:
$f = drupal_get_form('example_module_form', $node);
$f['#weight'] = 1;
$node->content['data_collection_form'] = $f;
Run Code Online (Sandbox Code Playgroud)
如果您确实希望以另一种方式执行此操作,则表单应该是可渲染的"元素",因此该键不应以前缀为前缀#:
$f = drupal_get_form('example_module_form', $node);
$node->content['data_collection_form'] = array(0 => $f, '#weight' => 1);
Run Code Online (Sandbox Code Playgroud)
带有前缀的前导数组的渲染数组中的所有条目#都被视为属性,而不被视为属性的渲染数组中的所有条目都被视为"子级"并且是递归渲染的.
克莱夫的回答在我的案例中不起作用.我需要调用drupal_render并将其作为标记传递.
$form = drupal_get_form('example_module_form', $node);
$node->content['data_collection_form'] = array(
'#markup' => drupal_render($form),
'#weight' => 10,
);
Run Code Online (Sandbox Code Playgroud)
这项工作,但我不确定这是否正确.