function _editor_record_file_usage

Same name and namespace in other branches
  1. 10 core/modules/editor/editor.module \_editor_record_file_usage()
  2. 9 core/modules/editor/editor.module \_editor_record_file_usage()
  3. 8.9.x core/modules/editor/editor.module \_editor_record_file_usage()

Records file usage of files referenced by formatted text fields.

Every referenced file that is temporally saved will be resaved as permanent.

Parameters

array $uuids: An array of file entity UUIDs.

\Drupal\Core\Entity\EntityInterface $entity: An entity whose fields to inspect for file references.

Deprecated

in drupal:11.4.0 and is removed from drupal:12.0.0. No replacement is provided.

See also

https://www.drupal.org/node/3568136

File

core/modules/editor/editor.module, line 143

Code

function _editor_record_file_usage(array $uuids, EntityInterface $entity) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. No replacement is provided. See https://www.drupal.org/node/3568136', E_USER_DEPRECATED);
  foreach ($uuids as $uuid) {
    if ($file = \Drupal::service('entity.repository')->loadEntityByUuid('file', $uuid)) {
      /** @var \Drupal\file\FileInterface $file */
      if ($file->isTemporary()) {
        $file->setPermanent();
        $file->save();
      }
      \Drupal::service('file.usage')->add($file, 'editor', $entity->getEntityTypeId(), $entity->id());
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.