function hook_ENTITY_TYPE_update
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_update()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_update()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_update()
Respond to updates to an entity of a particular type.
This hook runs once the entity storage has been updated. Note that hook implementations may not alter the stored entity data. Get the original entity object from $entity->original.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
See also
Related topics
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1252
Code
function hook_ENTITY_TYPE_update(\Drupal\Core\Entity\EntityInterface $entity) {
// Update the entity's entry in a fictional table of this type of entity.
\Drupal::database()->update('example_entity')
->fields([
'updated' => REQUEST_TIME,
])
->condition('id', $entity->id())
->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.