You are here

function file_entity_multiple_delete_form in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.pages.inc \file_entity_multiple_delete_form()

Form constructor for file deletion confirmation form.

Parameters

array $files: An array of file objects.

File

./file_entity.pages.inc, line 1159
Supports file operations including View, Edit, and Delete.

Code

function file_entity_multiple_delete_form($form, &$form_state, array $files) {
  $form['files'] = array(
    '#prefix' => '<ul>',
    '#suffix' => '</ul>',
    '#tree' => TRUE,
  );
  $files_have_usage = FALSE;
  foreach ($files as $fid => $file) {
    $title = entity_label('file', $file);
    $usage = file_usage_list($file);
    if (!empty($usage)) {
      $files_have_usage = TRUE;
      $title = t('@title (in use)', array(
        '@title' => $title,
      ));
    }
    else {
      $title = check_plain($title);
    }
    $form['files'][$fid] = array(
      '#type' => 'hidden',
      '#value' => $fid,
      '#prefix' => '<li>',
      '#suffix' => $title . "</li>\n",
    );
  }
  $form['operation'] = array(
    '#type' => 'hidden',
    '#value' => 'delete',
  );
  $description = t('This action cannot be undone.');
  if ($files_have_usage) {
    $description .= ' ' . t('Some of the files are currently in use and may cause problems if deleted.');
  }
  return confirm_form($form, format_plural(count($files), 'Are you sure you want to delete this file?', 'Are you sure you want to delete these files?'), 'admin/content/file', $description, t('Delete'));
}