You are here

function hook_entity_predelete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_predelete()

Act before entity deletion.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object for the entity that is about to be deleted.

See also

hook_ENTITY_TYPE_predelete()

Related topics

3 functions implement hook_entity_predelete()

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

comment_entity_predelete in core/modules/comment/comment.module
Implements hook_entity_predelete().
entity_crud_hook_test_entity_predelete in core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_entity_predelete().
entity_test_entity_predelete in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_predelete().
1 invocation of hook_entity_predelete()
EntityStorageBase::delete in core/lib/Drupal/Core/Entity/EntityStorageBase.php
Deletes permanently saved entities.

File

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

Code

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

  // Count references to this entity in a custom table before they are removed
  // upon entity deletion.
  $id = $entity
    ->id();
  $type = $entity
    ->getEntityTypeId();
  $count = db_select('example_entity_data')
    ->condition('type', $type)
    ->condition('id', $id)
    ->countQuery()
    ->execute()
    ->fetchField();

  // Log the count in a table that records this statistic for deleted entities.
  db_merge('example_deleted_entity_statistics')
    ->key(array(
    'type' => $type,
    'id' => $id,
  ))
    ->fields(array(
    'count' => $count,
  ))
    ->execute();
}