function _editor_record_file_usage in Drupal 8
Same name and namespace in other branches
- 9 core/modules/editor/editor.module \_editor_record_file_usage()
Records file usage of files referenced by formatted text fields.
Every referenced file that does not yet have the FILE_STATUS_PERMANENT state, will be given that state.
Parameters
array $uuids: An array of file entity UUIDs.
\Drupal\Core\Entity\EntityInterface $entity: An entity whose fields to inspect for file references.
2 calls to _editor_record_file_usage()
- editor_entity_insert in core/
modules/ editor/ editor.module - Implements hook_entity_insert().
- editor_entity_update in core/
modules/ editor/ editor.module - Implements hook_entity_update().
File
- core/
modules/ editor/ editor.module, line 455 - Adds bindings for client-side "text editors" to text formats.
Code
function _editor_record_file_usage(array $uuids, EntityInterface $entity) {
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());
}
}
}