FileUsageBase::delete

public FileUsageBase::delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1)

Removes a record to indicate that a module is no longer using a file.

Parameters

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

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

string $type: (optional) The type of the object that contains the referenced file. May be omitted if all module references to a file are being deleted. Defaults to NULL.

int $id: (optional) The unique, numeric ID of the object containing the referenced file. May be omitted if all module references to a file are being deleted. Defaults to NULL.

int $count: (optional) The number of references to delete from the object. Defaults to 1. Zero may be specified to delete all references to the file within a specific object.

Overrides FileUsageInterface::delete

File

core/modules/file/src/FileUsage/FileUsageBase.php, line 26

Class

FileUsageBase
Defines the base class for database file usage backend.

Namespace

Drupal\file\FileUsage

Code

public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) {
  // If there are no more remaining usages of this file, mark it as temporary,
  // which result in a delete through system_cron().
  $usage = \Drupal::service('file.usage')->listUsage($file);
  if (empty($usage)) {
    $file->setTemporary();
    $file->save();
  }
}
doc_Drupal
2016-10-29 09:14:04
Comments
Leave a Comment

Please login to continue.