You are here

function _auditfiles_referenced_not_used_confirm_operation in Audit Files 7.3

Same name and namespace in other branches
  1. 7.4 auditfiles.referencednotused.inc \_auditfiles_referenced_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_referenced_not_used_confirm_operation()
auditfiles_referenced_not_used_form in ./auditfiles.referencednotused.inc
Generates the report.

File

./auditfiles.referencednotused.inc, line 485
Generates report showing files referenced by content, but not in file_usage.

Code

function _auditfiles_referenced_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 $reference_id) {
      if (!empty($reference_id)) {
        $reference_id_parts = explode('.', $reference_id);
        if ($values['op'] == t('Add selected items to the file_usage table')) {
          $message = t('will be added to the file_usage table.');
        }
        elseif ($values['op'] == t('Delete selected references')) {
          $message = t('will be deleted from the content.');
        }
        $form['changelist'][$reference_id] = array(
          '#type' => 'hidden',
          '#value' => $reference_id,
          '#prefix' => '<li>' . t('File ID') . ' <strong>' . $reference_id_parts[4] . '</strong> ' . $message,
          '#suffix' => "</li>\n",
        );
      }
      else {

        // Unsetting the unprocessed files prevents confirm_submit from dealing
        // with them.
        unset($form_state['values']['files'][$reference_id]);
      }
    }
  }
  $form['operation'] = array(
    '#type' => 'hidden',
  );
  if ($values['op'] == t('Add selected items to the file_usage table')) {
    $form['operation']['#value'] = 'add';
    $confirm_question = t('Add these files to the file_usage table?');
    $confirm_description = '';
  }
  elseif ($values['op'] == t('Delete selected references')) {
    $form['operation']['#value'] = 'delete';
    $confirm_question = t('Delete these references from their content?');
    $confirm_description = '<strong>' . t('This action cannot be undone.') . '</strong>';
  }

  // 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/referencednotused',
  );
  return confirm_form($form, $confirm_question, 'admin/reports/auditfiles/referencednotused', $confirm_description, t('Yes'), t('No'));
}