public function DatabaseFileUsageBackend::listUsage in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage()
- 10 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 123
Class
- DatabaseFileUsageBackend
- Defines the database file usage backend. This is the default Drupal backend.
Namespace
Drupal\file\FileUsageCode
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;
}