You are here

function hook_entity_update in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_update()
  2. 7 modules/system/system.api.php \hook_entity_update()
  3. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_update()

Respond to updates to an entity.

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_TYPE_update()

Related topics

6 functions implement hook_entity_update()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

content_moderation_entity_update in core/modules/content_moderation/content_moderation.module
Implements hook_entity_update().
editor_entity_update in core/modules/editor/editor.module
Implements hook_entity_update().
editor_test_entity_update in core/modules/editor/tests/modules/editor_test.module
Implements hook_entity_update().
entity_crud_hook_test_entity_update in core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_entity_update().
entity_test_entity_update in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_update().

... See full list

1 invocation of hook_entity_update()
ConfigEntityStorageTest::testSaveUpdate in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@covers ::save @covers ::doSave

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1194
Hooks and documentation related to entities.

Code

function hook_entity_update(\Drupal\Core\Entity\EntityInterface $entity) {

  // Update the entity's entry in a fictional table of all entities.
  \Drupal::database()
    ->update('example_entity')
    ->fields([
    'updated' => REQUEST_TIME,
  ])
    ->condition('type', $entity
    ->getEntityTypeId())
    ->condition('id', $entity
    ->id())
    ->execute();
}