function hook_entity_insert

You are here

7 system.api.php hook_entity_insert($entity, $type)
8 entity.api.php hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity)

Act on entities when inserted.

Parameters

$entity: The entity object.

$type: The type of entity being inserted (i.e. node, user, comment).

Related topics

1 function implements hook_entity_insert()

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

entity_crud_hook_test_entity_insert in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_entity_insert().
6 invocations of hook_entity_insert()
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
field_attach_insert in modules/field/field.attach.inc
Save field data for a new entity.
file_save in includes/file.inc
Saves a file object to the database.
taxonomy_vocabulary_save in modules/taxonomy/taxonomy.module
Saves a vocabulary.
user_save in modules/user/user.module
Save changes to a user account or add a new user.

... See full list

File

modules/system/system.api.php, line 328
Hooks provided by Drupal core and the System module.

Code

function hook_entity_insert($entity, $type) {
  // Insert the new entity into a fictional table of all entities.
  $info = entity_get_info($type);
  list($id) = entity_extract_ids($type, $entity);
  db_insert('example_entity')->fields(array(
    'type' => $type,
    'id' => $id,
    'created' => REQUEST_TIME,
    'updated' => REQUEST_TIME,
  ))->execute();
}