function hook_field_delete_revision

Define custom revision delete behavior for this module's field types.

This hook is invoked just before the data is deleted from field storage in field_attach_delete_revision(), and will only be called for fieldable types that are versioned.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for the operation.

$field: The field structure for the operation.

$instance: The instance structure for $field on $entity's bundle.

$langcode: The language associated with $items.

$items: $entity->{$field['field_name']}[$langcode], or an empty array if unset.

Related topics

2 functions implement hook_field_delete_revision()

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

file_field_delete_revision in drupal/core/modules/file/file.field.inc
Implements hook_field_delete_revision().
image_field_delete_revision in drupal/core/modules/image/image.field.inc
Implements hook_field_delete_revision().
1 invocation of hook_field_delete_revision()
field_attach_delete_revision in drupal/core/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

drupal/core/modules/field/field.api.php, line 616

Code

function hook_field_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, $field, $instance, $langcode, &$items) {
  foreach ($items as $delta => $item) {

    // Decrement the file usage count by 1.
    file_usage()
      ->delete(file_load($item['fid']), 'file', $entity
      ->entityType(), $entity
      ->id());
  }
}