function hook_ENTITY_TYPE_insert
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_insert()
- 10 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
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1161
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' => REQUEST_TIME,
'updated' => REQUEST_TIME,
])
->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.