You are here

function _auditfiles_managed_not_used_confirm_operation in Audit Files 7.4

Same name and namespace in other branches
  1. 7.3 auditfiles.managednotused.inc \_auditfiles_managed_not_used_confirm_operation()

Presents a confimation form to verify the user wants to complete the action.

Parameters

array $form: The form definition.

array $form_state: The current state of the form.

Return value

array A form array for a confirmation form.

1 call to _auditfiles_managed_not_used_confirm_operation()
auditfiles_managed_not_used_form in ./auditfiles.managednotused.inc
Generates the report.

File

./auditfiles.managednotused.inc, line 371
Generates a report showing files in file_managed, but not in file_usage.

Code

function _auditfiles_managed_not_used_confirm_operation(array $form, array &$form_state) {
  $values = $form_state['values'];
  $form['changelist'] = array(
    '#prefix' => '<ul>',
    '#suffix' => '</ul>',
    '#tree' => TRUE,
  );

  // Prepare the list of items to present to the user.
  if (!empty($values['files'])) {
    foreach ($values['files'] as $file_id) {
      if (!empty($file_id)) {
        $file = file_load($file_id);
        if (!empty($file)) {
          $form['changelist'][$file_id] = array(
            '#type' => 'hidden',
            '#value' => $file_id,
            '#prefix' => '<li><strong>' . $file->filename . '</strong> ' . t('will be deleted from the file_managed table.'),
            '#suffix' => "</li>\n",
          );
        }
      }
      else {

        // Unsetting the unprocessed files prevents confirm_submit from dealing
        // with them.
        unset($form_state['values']['files'][$file_id]);
      }
    }
  }
  $form['operation'] = array(
    '#type' => 'hidden',
    '#value' => 'delete',
  );

  // Tell the submit handler to process the confirmation.
  $form['process'] = array(
    '#type' => 'hidden',
    '#value' => 'TRUE',
  );

  // Go back to the main form, when done with this one.
  $form['destination'] = array(
    '#type' => 'hidden',
    '#value' => 'admin/reports/auditfiles/managednotused',
  );
  return confirm_form($form, t('Delete these items from the file_managed table?'), 'admin/reports/auditfiles/managednotused', '<strong>' . t('This action cannot be undone.') . '</strong>', t('Yes'), t('No'));
}