function DatabaseFileUsageBackend::add

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

Overrides FileUsageBase::add

File

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

Class

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

Namespace

Drupal\file\FileUsage

Code

public function add(FileInterface $file, $module, $type, $id, $count = 1) {
    $this->connection
        ->merge($this->tableName)
        ->keys([
        'fid' => $file->id(),
        'module' => $module,
        'type' => $type,
        'id' => $id,
    ])
        ->fields([
        'count' => $count,
    ])
        ->expression('count', '[count] + :count', [
        ':count' => $count,
    ])
        ->execute();
    parent::add($file, $module, $type, $id, $count);
}

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