如何在drupal 8上设置文件使用率?以及如何在drupal 8中使用以下方法?
答案 0 :(得分:0)
在这里,我为Drupal 7和Drupal 8添加了等效的语法
file_usage_add -> \Drupal::service('file.usage')->add
file_usage_delete -> \Drupal::service('file.usage')->delete
file_usage_list -> \Drupal::service('file.usage')->listUsage
//Add / Delete file usage
$entity_type = 'node';
$entity_id = 1;//Node ID
$fid = 1; // The file ID
$file = \Drupal\file\Entity\File::load($fid);
$file_usage = \Drupal::service('file.usage');
$file_usage->add($file, 'mymodule', $entity_type, $entity_id);
$list = $file_usage->listUsage($file);
$file_usage->delete($file, 'mymodule', $entity_type, $entity_id)
//Get usage of a file
$file = \Drupal\file\Entity\File::load($fid);
$file_usage = \Drupal::service('file.usage');
$list = $file_usage->listUsage($file);
答案 1 :(得分:0)
您可以在Drupal 8中使用以下方法:
\Drupal::service('file.usage')->add
\Drupal::service('file.usage')->delete
\Drupal::service('file.usage')->listUsage