Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_insert()
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_insert()
Respond to creation of a new entity of a particular type.
This hook runs once the entity has been stored. Note that hook implementations may not alter the stored entity data.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
See also
Related topics
47 functions implement hook_ENTITY_TYPE_insert()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- block_content_test_block_content_insert in core/
modules/ block_content/ tests/ modules/ block_content_test/ block_content_test.module - Implements hook_block_content_insert().
- book_node_insert in core/
modules/ book/ book.module - Implements hook_ENTITY_TYPE_insert() for node entities.
- comment_entity_insert in core/
modules/ comment/ comment.module - Implements hook_entity_insert().
- comment_field_storage_config_insert in core/
modules/ comment/ comment.module - Implements hook_ENTITY_TYPE_insert() for 'field_storage_config'.
- config_test_config_test_insert in core/
modules/ config/ tests/ config_test/ config_test.hooks.inc - Implements hook_config_test_insert().
File
- core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1197 - Hooks and documentation related to entities.
Code
function hook_ENTITY_TYPE_insert(\Drupal\Core\Entity\EntityInterface $entity) {
// Insert the new entity into a fictional table of this type of entity.
\Drupal::database()
->insert('example_entity')
->fields([
'id' => $entity
->id(),
'created' => \Drupal::time()
->getRequestTime(),
'updated' => \Drupal::time()
->getRequestTime(),
])
->execute();
}