function hook_file_predelete

Act prior to file deletion.

This hook is invoked when deleting a file before the file is removed from the filesystem and before its records are removed from the database.

Parameters

Drupal\file\File $file: The file that is about to be deleted.

See also

hook_file_delete()

Drupal\file\FileStorageController::delete()

upload_file_delete()

4 functions implement hook_file_predelete()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_file_predelete in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_file_predelete().
file_file_predelete in drupal/core/modules/file/file.module
Implements hook_file_predelete().
file_test_file_predelete in drupal/core/modules/file/tests/file_test/file_test.module
Implements hook_file_predelete().
image_file_predelete in drupal/core/modules/image/image.module
Implements hook_file_predelete().

File

drupal/core/modules/file/file.api.php, line 166
Hooks for file module.

Code

function hook_file_predelete(Drupal\file\File $file) {

  // Delete all information associated with the file.
  db_delete('upload')
    ->condition('fid', $file->fid)
    ->execute();
}