function hook_insert

Respond to creation of a new node.

This hook is invoked only on the module that defines the node's content type (use hook_node_insert() to act on all node insertions).

This hook is invoked from node_save() after the node is inserted into the node table in the database, before field_attach_insert() is called, and before hook_node_insert() is invoked.

Parameters

Drupal\node\Node $node: The node that is being created.

Related topics

42 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.

ajax_command_insert in drupal/core/includes/ajax.inc
Creates a Drupal Ajax 'insert' command using the method in #ajax['method'].
book_node_insert in drupal/core/modules/book/book.module
Implements hook_node_insert().
comment_node_insert in drupal/core/modules/comment/comment.module
Implements hook_node_insert().
comment_node_type_insert in drupal/core/modules/comment/comment.module
Implements hook_node_type_insert().
config_test_config_test_insert in drupal/core/modules/config/tests/config_test/config_test.hooks.inc
Implements hook_config_test_insert().

... See full list

File

drupal/core/modules/node/node.api.php, line 1173
Hooks provided by the Node module.

Code

function hook_insert(Drupal\node\Node $node) {
  db_insert('mytable')
    ->fields(array(
    'nid' => $node->nid,
    'extra' => $node->extra,
  ))
    ->execute();
}