1 file.pages.inc file_delete_form($form, &$form_state, File $file)

Page callback: Form constructor for the file deletion confirmation form.

Path: file/%file/delete

Parameters

File $file: A file object from file_load().

See also

file_menu()

File

core/modules/file/file.pages.inc, line 782
Supports file operations including Manage and Delete.

Code

function file_delete_form($form, &$form_state, File $file) {
  $form_state['file'] = $file;

  $form['fid'] = array(
    '#type' => 'value',
    '#value' => $file->fid,
  );

  $description = '';
  $known_count = 0;
  $unknown_count = 0;
  $entity_list = _file_usage_list_links($file, $known_count, $unknown_count);

  if ($known_count || $unknown_count) {
    $description .= format_plural($known_count + $unknown_count, 'This file is referenced by one piece of content.', 'This file is referenced by @count pieces of content.');
  }

  if ($entity_list) {
    if ($unknown_count) {
      $entity_list[] = format_plural($unknown_count, 'And one additional unknown piece of content.', 'And @count additional unknown pieces of content.');
    }
    $description .= ' ' . t('Content referencing this file includes:');
    $description = '<p>' . $description . '</p>';
    $description .= theme('item_list', array('items' => $entity_list));
  }
  elseif ($unknown_count) {
    $description .= ' ' . t('However, this content is either missing or you do not have access to it.');
    $description = '<p>' . $description . '</p>';
  }
  else {
    $description .= t('This file has no known content referencing it, although it may still be in use.');
    $description = '<p>' . $description . '</p>';
  }
  $description .= '<p>' . t('Deleting this file may cause content to display improperly.') . '</p>';

  return confirm_form($form, 
  t('Are you sure you want to delete the file %title?', array(
    '%title' => entity_label('file', $file),
  )), 
  'admin/content/files', 
  $description, 
  t('Delete')
  );
}