DatabaseFileUsageBackend::add

public DatabaseFileUsageBackend::add(FileInterface $file, $module, $type, $id, $count = 1)

Records that a module is using a file.

Examples:

  • A module that associates files with nodes, so $type would be 'node' and $id would be the node's nid. Files for all revisions are stored within a single nid.
  • The User module associates an image with a user, so $type would be 'user' and the $id would be the user's uid.

Parameters

\Drupal\file\FileInterface $file: A file entity.

string $module: The name of the module using the file.

string $type: The type of the object that contains the referenced file.

int $id: The unique, numeric ID of the object containing the referenced file.

int $count: (optional) The number of references to add to the object. Defaults to 1.

Overrides FileUsageBase::add

File

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

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(array(
      'fid' => $file->id(),
      'module' => $module,
      'type' => $type,
      'id' => $id,
    ))
    ->fields(array('count' => $count))
    ->expression('count', 'count + :count', array(':count' => $count))
    ->execute();

  parent::add($file, $module, $type, $id, $count);
}
doc_Drupal
2016-10-29 08:59:45
Comments
Leave a Comment

Please login to continue.