DatabaseFileUsageBackend::listUsage

public DatabaseFileUsageBackend::listUsage(FileInterface $file)

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 98

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;
}
doc_Drupal
2016-10-29 08:59:45
Comments
Leave a Comment

Please login to continue.