abstract class FileUsageBase implements FileUsageInterface (View source)

Defines the base class for database file usage backend.

Properties

protected ConfigFactoryInterface $configFactory

The config factory.

Methods

__construct(ConfigFactoryInterface $config_factory = NULL)

Creates a FileUsageBase object.

add(FileInterface $file, string $module, string $type, string $id, int $count = 1)

Records that a module is using a file.

delete(FileInterface $file, string $module, string $type = NULL, string $id = NULL, int $count = 1)

Removes a record to indicate that a module is no longer using a file.

Details

__construct(ConfigFactoryInterface $config_factory = NULL)

Creates a FileUsageBase object.

Update the docblock and make $config_factory required in https://www.drupal.org/project/drupal/issues/3070114 when the drupal:9.0.x branch is opened.

Parameters

ConfigFactoryInterface $config_factory

The config factory. This parameter is required as of drupal:8.4.0 and trigger a fatal error if not passed in drupal:9.0.0.

add(FileInterface $file, string $module, string $type, string $id, int $count = 1)

Records that a module is using a file.

Examples:

  • A module that associates files with nodes, so $type would be 'node' and $id would be the node's nid. Files for all revisions are stored within a single nid.
  • The User module associates an image with a user, so $type would be 'user' and the $id would be the user's uid.

Parameters

FileInterface $file

A file entity.

string $module

The name of the module using the file.

string $type

The type of the object that contains the referenced file.

string $id

The unique ID of the object containing the referenced file.

int $count

(optional) The number of references to add to the object. Defaults to 1.

delete(FileInterface $file, string $module, string $type = NULL, string $id = NULL, int $count = 1)

Removes a record to indicate that a module is no longer using a file.

Parameters

FileInterface $file

A file entity.

string $module

The name of the module using the file.

string $type

(optional) The type of the object that contains the referenced file. May be omitted if all module references to a file are being deleted. Defaults to NULL.

string $id

(optional) The unique ID of the object containing the referenced file. May be omitted if all module references to a file are being deleted. Defaults to NULL.

int $count

(optional) The number of references to delete from the object. Defaults to 1. Zero may be specified to delete all references to the file within a specific object.