function hook_insert

You are here

7 node.api.php hook_insert($node)
4.6 node.php hook_insert($node)
4.7 node.php hook_insert($node)
5 node.php hook_insert($node)
6 node.php hook_insert($node)

Respond to node insertion.

This is a hook used by node modules. It is called to allow the module to take action when a new node is being inserted in the database by, for example, inserting information into related tables.

Parameters

$node: The node being inserted.

Return value

None.

To take action when nodes of any type are inserted (not just nodes of the type(s) defined by this module), use hook_nodeapi() instead.

For a detailed usage example, see node_example.module.

Related topics

2 functions implement hook_insert()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

poll_insert in modules/poll/poll.module
Implementation of hook_insert().
search_query_insert in modules/search/search.module
Return a query with the given module-specific search option inserted in. e.g. 'type:book'.
3 invocations of hook_insert()
node_type_save in modules/node/node.module
Saves a node type to the database.
taxonomy_save_vocabulary in modules/taxonomy/taxonomy.module
user_save in modules/user/user.module
Save changes to a user account or add a new user.

File

developer/hooks/node.php, line 295
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_insert($node) {
  db_query("INSERT INTO {mytable} (nid, extra)
    VALUES (%d, '%s')", $node->nid, $node->extra);
}

Comments

The $node->vid and $node->nid variables are generated automatically by the Drupal API.

If you are wondering, hook_insert() gets called before hook_nodeapi() with op=insert.
see http://api.drupal.org/api/function/node_save/6