Posted by premier23 on December 26, 2012 at 3:01pm
Hi,
I have an existing node which has additional fields.
Now I want to add a form programmatically to its "body".
To be clear: its just for a single node and not to all nodes of that type.
Which is the best way?
Comments
hook_node_view
hardcode solution:
<?phpfunction my_module_node_view() {
if ($node->nid == 12345) {
$node->content['my_form'] = array(
'#markup' => drupal_render(drupal_get_form('my_custom_form')),
'#weight' => 5,
);
}
}
?>
thanks for the answer. Is it
thanks for the answer.
Is it possible to inject the form in the body-field?
Easy
<?phpfunction my_module_node_view($node, $view_mode, $langcode) {
if ($node->type == 'article' && $view_mode == 'full') {
$node->content['body'][0]['#markup'] .= drupal_render(drupal_get_form('my_custom_form')),
}
}
?>