function DatabaseFileUsageBackend::listUsage

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

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;
}

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