function _webform_delete_file_usage in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.editor.inc \_webform_delete_file_usage()
Deletes file usage of files referenced by formatted text fields.
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.
int $count: The number of references to delete. Should be 1 when deleting a single revision and 0 when deleting an entity entirely.
Throws
\Drupal\Core\Entity\EntityStorageException
See also
\Drupal\file\FileUsage\FileUsageInterface::delete()
6 calls to _webform_delete_file_usage()
- TextFormat::postDelete in src/
Plugin/ WebformElement/ TextFormat.php - Delete any additional value associated with an element.
- 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_delete in includes/
webform.editor.inc - Implements hook_webform_delete().
- webform_webform_update in includes/
webform.editor.inc - Implements hook_webform_update().
- _webform_config_delete in includes/
webform.editor.inc - Delete config editor file references.
File
- includes/
webform.editor.inc, line 202 - Webform module editor file upload hooks.
Code
function _webform_delete_file_usage(array $uuids, $type, $id, $count) {
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');
$make_unused_managed_files_temporary = \Drupal::config('webform.settings')
->get('html_editor.make_unused_managed_files_temporary');
foreach ($uuids as $uuid) {
if ($file = $entity_repository
->loadEntityByUuid('file', $uuid)) {
$file_usage
->delete($file, 'editor', $type, $id, $count);
// Make unused files temporary.
if ($make_unused_managed_files_temporary && empty($file_usage
->listUsage($file)) && !$file
->isTemporary()) {
$file
->setTemporary();
$file
->save();
}
}
}
}