function _webform_record_file_usage in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.editor.inc \_webform_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.
string $type: The type of the object that contains the referenced file.
string $id: The unique ID of the object containing the referenced file.
Throws
\Drupal\Core\Entity\EntityStorageException
See also
4 calls to _webform_record_file_usage()
- TextFormat::postSave in src/
Plugin/ WebformElement/ TextFormat.php - Acts on a saved webform submission element before the insert or update hook is invoked.
- webform_webform_insert in includes/
webform.editor.inc - Implements hook_webform_insert().
- webform_webform_update in includes/
webform.editor.inc - Implements hook_webform_update().
- _webform_config_update in includes/
webform.editor.inc - Update config editor file references.
File
- includes/
webform.editor.inc, line 162 - Webform module editor file upload hooks.
Code
function _webform_record_file_usage(array $uuids, $type, $id) {
if (empty($uuids) || !\Drupal::moduleHandler()
->moduleExists('file')) {
return;
}
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
/** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
$file_usage = \Drupal::service('file.usage');
foreach ($uuids as $uuid) {
if ($file = $entity_repository
->loadEntityByUuid('file', $uuid)) {
if ($file->status !== FILE_STATUS_PERMANENT) {
$file->status = FILE_STATUS_PERMANENT;
$file
->save();
}
$file_usage
->add($file, 'editor', $type, $id);
}
}
}