| 7 node.api.php | hook_node_insert($node) |
| 8 node.api.php | hook_node_insert($node) |
Respond to creation of a new node.
This hook is invoked from node_save() after the node is inserted into the node table in the database, after the type-specific hook_insert() is invoked, and after field_attach_insert() is called.
Parameters
$node: The node that is being created.
Related topics
13 functions implement hook_node_insert()
File
- modules/
node/ node.api.php, line 510 - Hooks provided by the Node module.
Code
<?php
function hook_node_insert($node) {
db_insert('mytable')
->fields(array(
'nid' => $node->nid,
'extra' => $node->extra,
))
->execute();
}
?> Login or register to post comments
Comments
Undefined Property
I'm testing for a specific form id inside hook_node_insert like so:
<?php
function my_node_insert($node){
if($node->form_id == 'whatever_node_form')
... ...
?>
But I'm getting an error saying
Notice: Undefined property: stdClass::$form_id in my_node_insert()Where does it go wrong? Is there a different way I should test for a form id?
herp
Make sure you test your variables for existence.
<?phpfunction mymodule_node_insert($node){
if(isset($node->form_id) && ($node->form_id == 'whatever_node_form')){
// do stuff
}
}
?>
Not here
This is not the place to look for advice. Post in the forums, please.