You are here

function hook_field_storage_delete_revision in Drupal 7

Delete a single revision of field data for an entity.

This hook is invoked from field_attach_delete_revision() to ask the field storage module to delete field revision data.

Deleting the current (most recently written) revision is not allowed as has undefined results.

Parameters

$entity_type: The entity type of entity, such as 'node' or 'user'.

$entity: The entity on which to operate. The revision to delete is indicated by the entity's revision ID property, as identified by hook_fieldable_info() for $entity_type.

$fields: An array listing the fields to delete. The keys and values of the array are field IDs.

Related topics

2 functions implement hook_field_storage_delete_revision()

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

field_sql_storage_field_storage_delete_revision in modules/field/modules/field_sql_storage/field_sql_storage.module
Implements hook_field_storage_delete_revision().
field_test_field_storage_delete_revision in modules/field/tests/field_test.storage.inc
Implements hook_field_storage_delete_revision().
1 invocation of hook_field_storage_delete_revision()
field_attach_delete_revision in modules/field/field.attach.inc
Delete field data for a single revision of an existing entity. The passed entity must have a revision id attribute.

File

modules/field/field.api.php, line 1976
Hooks provided by the Field module.

Code

function hook_field_storage_delete_revision($entity_type, $entity, $fields) {
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  if (isset($vid)) {
    foreach ($fields as $field_id) {
      $field = field_info_field_by_id($field_id);
      $revision_name = _field_sql_storage_revision_tablename($field);
      db_delete($revision_name)
        ->condition('entity_type', $entity_type)
        ->condition('entity_id', $id)
        ->condition('revision_id', $vid)
        ->execute();
    }
  }
}