_editor_record_file_usage

_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.

Parameters

array $uuids: An array of file entity UUIDs.

EntityInterface $entity: An entity whose fields to inspect for file references.

File

core/modules/editor/editor.module, line 437
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::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());
    }
  }
}
doc_Drupal
2016-10-29 09:57:12
Comments
Leave a Comment

Please login to continue.