3 namespace Drupal\file\FileUsage;
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\file\FileInterface;
9 * Defines the base class for database file usage backend.
11 abstract class FileUsageBase implements FileUsageInterface {
16 * @var \Drupal\Core\Config\ConfigFactoryInterface
18 protected $configFactory;
21 * Creates a FileUsageBase object.
23 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
24 * (optional) The config factory. Defaults to NULL and will use
25 * \Drupal::configFactory() instead.
27 * @deprecated The $config_factory parameter will become required in Drupal
30 public function __construct(ConfigFactoryInterface $config_factory = NULL) {
31 $this->configFactory = $config_factory ?: \Drupal::configFactory();
37 public function add(FileInterface $file, $module, $type, $id, $count = 1) {
38 // Make sure that a used file is permanent.
39 if (!$file->isPermanent()) {
40 $file->setPermanent();
48 public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) {
49 // Do not actually mark files as temporary when the behavior is disabled.
50 if (!$this->configFactory->get('file.settings')->get('make_unused_managed_files_temporary')) {
53 // If there are no more remaining usages of this file, mark it as temporary,
54 // which result in a delete through system_cron().
55 $usage = \Drupal::service('file.usage')->listUsage($file);
57 $file->setTemporary();