Same name and namespace in other branches
  1. 8.9.x core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage()
  2. 9 core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage()

Determines where a file is used.

Parameters

\Drupal\file\FileInterface $file: A file entity.

Return value

array A nested array with usage data. The first level is keyed by module name, the second by object type and the third by the object id. The value of the third level contains the usage count.

Overrides FileUsageInterface::listUsage

File

core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php, line 101

Class

DatabaseFileUsageBackend
Defines the database file usage backend. This is the default Drupal backend.

Namespace

Drupal\file\FileUsage

Code

public function listUsage(FileInterface $file) {
  $result = $this->connection
    ->select($this->tableName, 'f')
    ->fields('f', [
    'module',
    'type',
    'id',
    'count',
  ])
    ->condition('fid', $file
    ->id())
    ->condition('count', 0, '>')
    ->execute();
  $references = [];
  foreach ($result as $usage) {
    $references[$usage->module][$usage->type][$usage->id] = $usage->count;
  }
  return $references;
}