function hook_entity_insert

Act on entities when inserted.

Parameters

Drupal\Core\Entity\EntityInterface $entity: The entity object.

Related topics

2 functions implement hook_entity_insert()
3 invocations of hook_entity_insert()

File

drupal/core/includes/entity.api.php, line 91
Hooks provided the Entity module.

Code

function hook_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {

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