function EditorHooks::deleteFileUsage

Deletes file usage of files referenced by formatted text fields.

Parameters

array $uuids: An array of file entity UUIDs.

\Drupal\Core\Entity\EntityInterface $entity: An entity whose fields to inspect for file references.

int $count: The number of references to delete. Should be 1 when deleting a single revision and 0 when deleting an entity entirely.

See also

\Drupal\file\FileUsage\FileUsageInterface::delete()

3 calls to EditorHooks::deleteFileUsage()
EditorHooks::entityDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_delete().
EditorHooks::entityRevisionDelete in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_revision_delete().
EditorHooks::entityUpdate in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_entity_update().

File

core/modules/editor/src/Hook/EditorHooks.php, line 398

Class

EditorHooks
Hook implementations for editor.

Namespace

Drupal\editor\Hook

Code

protected function deleteFileUsage(array $uuids, EntityInterface $entity, int $count) : void {
  if (!\Drupal::getContainer()->has('file.usage')) {
    return;
  }
  $entity_repository = \Drupal::service('entity.repository');
  $file_usage = \Drupal::service('file.usage');
  foreach ($uuids as $uuid) {
    if ($file = $entity_repository->loadEntityByUuid('file', $uuid)) {
      $file_usage->delete($file, 'editor', $entity->getEntityTypeId(), $entity->id(), $count);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.