_editor_record_file_usage(array $uuids, EntityInterface $entity)
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.
array $uuids: An array of file entity UUIDs.
EntityInterface $entity: An entity whose fields to inspect for file references.
function _editor_record_file_usage(array $uuids, EntityInterface $entity) { foreach ($uuids as $uuid) { if ($file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid)) { if ($file->status !== FILE_STATUS_PERMANENT) { $file->status = FILE_STATUS_PERMANENT; $file->save(); } \Drupal::service('file.usage')->add($file, 'editor', $entity->getEntityTypeId(), $entity->id()); } } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!editor!editor.module/function/_editor_record_file_usage/8.1.x