3 namespace Drupal\file\FileUsage;
5 use Drupal\file\FileInterface;
8 * Defines the base class for database file usage backend.
10 abstract class FileUsageBase implements FileUsageInterface {
15 public function add(FileInterface $file, $module, $type, $id, $count = 1) {
16 // Make sure that a used file is permanent.
17 if (!$file->isPermanent()) {
18 $file->setPermanent();
26 public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) {
27 // If there are no more remaining usages of this file, mark it as temporary,
28 // which result in a delete through system_cron().
29 $usage = \Drupal::service('file.usage')->listUsage($file);
31 $file->setTemporary();