3 namespace Drupal\file\FileUsage;
5 use Drupal\file\FileInterface;
8 * File usage backend interface.
10 interface FileUsageInterface {
13 * Records that a module is using a file.
16 * - A module that associates files with nodes, so $type would be
17 * 'node' and $id would be the node's nid. Files for all revisions are
18 * stored within a single nid.
19 * - The User module associates an image with a user, so $type would be 'user'
20 * and the $id would be the user's uid.
22 * @param \Drupal\file\FileInterface $file
24 * @param string $module
25 * The name of the module using the file.
27 * The type of the object that contains the referenced file.
29 * The unique ID of the object containing the referenced file.
31 * (optional) The number of references to add to the object. Defaults to 1.
33 public function add(FileInterface $file, $module, $type, $id, $count = 1);
36 * Removes a record to indicate that a module is no longer using a file.
38 * @param \Drupal\file\FileInterface $file
40 * @param string $module
41 * The name of the module using the file.
43 * (optional) The type of the object that contains the referenced file. May
44 * be omitted if all module references to a file are being deleted. Defaults
47 * (optional) The unique ID of the object containing the referenced file.
48 * May be omitted if all module references to a file are being deleted.
51 * (optional) The number of references to delete from the object. Defaults
52 * to 1. Zero may be specified to delete all references to the file within a
55 public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1);
58 * Determines where a file is used.
60 * @param \Drupal\file\FileInterface $file
64 * A nested array with usage data. The first level is keyed by module name,
65 * the second by object type and the third by the object id. The value of
66 * the third level contains the usage count.
68 public function listUsage(FileInterface $file);