FileUsageBase.php in Drupal 10
File
core/modules/file/src/FileUsage/FileUsageBase.php
View source
<?php
namespace Drupal\file\FileUsage;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\file\FileInterface;
abstract class FileUsageBase implements FileUsageInterface {
protected $configFactory;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public function add(FileInterface $file, $module, $type, $id, $count = 1) {
if (!$file
->isPermanent()) {
$file
->setPermanent();
$file
->save();
}
}
public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) {
if (!$this->configFactory
->get('file.settings')
->get('make_unused_managed_files_temporary')) {
return;
}
$usage = \Drupal::service('file.usage')
->listUsage($file);
if (empty($usage)) {
$file
->setTemporary();
$file
->save();
}
}
}
Classes
Name |
Description |
FileUsageBase |
Defines the base class for database file usage backend. |