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()

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 drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_entity_insert().
translation_entity_entity_insert in drupal/core/modules/translation_entity/translation_entity.module
Implements hook_entity_insert().
4 invocations of hook_entity_insert()
ConfigStorageController::save in drupal/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
Implements Drupal\Core\Entity\EntityStorageControllerInterface::save().
DatabaseStorageController::save in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
Implements \Drupal\Core\Entity\EntityStorageControllerInterface::save().
DatabaseStorageControllerNG::save in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Overrides DatabaseStorageController::save().
MenuLinkStorageController::save in drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
Overrides DatabaseStorageController::save().

File

drupal/core/includes/entity.api.php, line 214
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();
}