function file_field_delete_file

7.x file.field.inc file_field_delete_file($item, $field, $entity_type, $id, $count = 1)

Decrements the usage count for a file and attempts to delete it.

This function only has an effect if the file being deleted is used only by File module.

Parameters

$item: The field item that contains a file array.

$field: The field structure for the operation.

$entity_type: The type of $entity.

$id: The entity ID which contains the file being deleted.

$count: (optional) The number of references to decrement from the object containing the file. Defaults to 1.

Return value

Boolean TRUE if the file was deleted, or an array of remaining references if the file is still in use by other modules. Boolean FALSE if an error was encountered.

5 calls to file_field_delete_file()
file_field_delete in drupal/modules/file/file.field.inc
Implements hook_field_delete().
file_field_delete_revision in drupal/modules/file/file.field.inc
Implements hook_field_delete_revision().
file_field_update in drupal/modules/file/file.field.inc
Implements hook_field_update().
hook_field_delete in drupal/modules/field/field.api.php
Define custom delete behavior for this module's field data.
hook_field_delete_revision in drupal/modules/field/field.api.php
Define custom revision delete behavior for this module's field types.

File

drupal/modules/file/file.field.inc, line 357
Field module functionality for the File module.

Code

function file_field_delete_file($item, $field, $entity_type, $id, $count = 1) {
  // To prevent the file field from deleting files it doesn't know about, check
  // the file reference count. Temporary files can be deleted because they
  // are not yet associated with any content at all.
  $file = (object) $item;
  $file_usage = file_usage_list($file);
  if ($file->status == 0 || !empty($file_usage['file'])) {
    file_usage_delete($file, 'file', $entity_type, $id, $count);
    return file_delete($file);
  }

  // Even if the file is not deleted, return TRUE to indicate the file field
  // record can be removed from the field database tables.
  return TRUE;
}