function hook_entity_insert
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_insert()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_insert()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_insert()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_insert()
Act on entities when inserted.
Parameters
$entity: The entity object.
$type: The type of entity being inserted (i.e. node, user, comment).
Related topics
9 functions implement hook_entity_insert()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- CommentHooks::entityInsert in core/
modules/ comment/ src/ Hook/ CommentHooks.php - Implements hook_entity_insert().
- ContentModerationHooks::entityInsert in core/
modules/ content_moderation/ src/ Hook/ ContentModerationHooks.php - Implements hook_entity_insert().
- ContentModerationTestResaveHooks::entityInsert in core/
modules/ content_moderation/ tests/ modules/ content_moderation_test_resave/ src/ Hook/ ContentModerationTestResaveHooks.php - Implements hook_entity_insert().
- EditorHooks::entityInsert in core/
modules/ editor/ src/ Hook/ EditorHooks.php - Implements hook_entity_insert().
- EntityCrudHookTestHooks::entityInsert in core/
modules/ system/ tests/ modules/ entity_crud_hook_test/ src/ Hook/ EntityCrudHookTestHooks.php - Implements hook_entity_insert().
4 invocations of hook_entity_insert()
- comment_save in modules/
comment/ comment.module - Accepts a submission of new or changed comment content.
- 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.
File
-
modules/
system/ system.api.php, line 328
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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.