function hook_ENTITY_TYPE_update

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

hook_entity_update()

Related topics

File

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

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.