8.5.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.0.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.1.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.2.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.3.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.4.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
8.6.x entity.api.php hook_entity_update(Drupal\Core\Entity\EntityInterface $entity)
7.x system.api.php hook_entity_update($entity, $type)

Act on entities when updated.

Parameters

$entity: The entity object.

$type: The type of entity being updated (i.e. node, user, comment).

Related topics

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

entity_crud_hook_test_entity_update in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_entity_update().
5 invocations of hook_entity_update()
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
field_attach_update in modules/field/field.attach.inc
Save field data for an existing entity.
taxonomy_vocabulary_save in modules/taxonomy/taxonomy.module
Saves a vocabulary.
user_save in modules/user/user.module
Save changes to a user account or add a new user.
user_save in modules/user/user.module
Save changes to a user account or add a new user.

File

modules/system/system.api.php, line 350
Hooks provided by Drupal core and the System module.

Code

function hook_entity_update($entity, $type) {

  // Update the entity's entry in a fictional table of all entities.
  $info = entity_get_info($type);
  list($id) = entity_extract_ids($type, $entity);
  db_update('example_entity')
    ->fields(array(
    'updated' => REQUEST_TIME,
  ))
    ->condition('type', $type)
    ->condition('id', $id)
    ->execute();
}

Comments

holtzermann17’s picture

Much as described in the comments on hook_node_update, I am getting OLD versions of the page contents in code that is run via hook_entity_update.

Unfortunately, the fix suggested in the hook_node_update thread viz.,

entity_get_controller('node')->resetCache(array($node->nid));

does not seem to have any useful effect for me.

More specifically: I want to retrieve the new XHTML and do something with it after the user presses save. But so far, no luck. If I view the page's source manually, it's all good - but if I run cURL inside this hook, I just get the OLD contents, which is not useful for me. Should I be using a different hook?

ymakux’s picture

Just a guess: you need to provide proper entity ID, for example for entity "commerce_product"

entity_get_controller('node')->resetCache(array($entity->product_id));

Not tested

ymakux’s picture

correction: entity_get_controller('commerce_product')

NancyDru’s picture

I know that at the time of hook_node_update() there is a $node->old object present, so you can compare what's new to what's old. Do a dump in hook_entity_update() and see if an analogous structure is present.

emptyvoid’s picture

Note based on comment above, consider using

hook_entity_insert() instead.

clintu’s picture

hook_entity_insert() will not help at the time of entity update. Please refer : http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...