You are here

public function DatabaseFileUsageBackend::listUsage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 103
Contains \Drupal\file\FileUsage\DatabaseFileUsageBackend.

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', array(
    'module',
    'type',
    'id',
    'count',
  ))
    ->condition('fid', $file
    ->id())
    ->condition('count', 0, '>')
    ->execute();
  $references = array();
  foreach ($result as $usage) {
    $references[$usage->module][$usage->type][$usage->id] = $usage->count;
  }
  return $references;
}