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. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_update()
  3. 10 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 1245

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' => \Drupal::time()->getRequestTime(),
    ])
        ->condition('id', $entity->id())
        ->execute();
}

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