function hook_ENTITY_TYPE_insert

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_insert()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_insert()
  3. 10 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

hook_entity_insert()

Related topics

1 function implements 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.

delay_cache_tags_invalidation_entity_test_insert in core/modules/system/tests/modules/delay_cache_tags_invalidation/delay_cache_tags_invalidation.module
Implements hook_ENTITY_TYPE_insert().

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1200

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.