file_field_delete_file

  1. drupal
    1. 8
    2. 7
Versions
8 – 7 file_field_delete_file($item, $field, $entity_type, $id, $count = 1)

Decrements a file usage count 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 functions call file_field_delete_file()

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

Code

modules/file/file.field.inc, line 337

<?php
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;
}
?>