You are here

function user_delete_form_alter in User Delete 5

Same name and namespace in other branches
  1. 6.2 user_delete.module \user_delete_form_alter()
  2. 6 user_delete.module \user_delete_form_alter()

Implementation of hook_form_alter().

File

./user_delete.module, line 61
User delete - Let users delete their own account.

Code

function user_delete_form_alter($form_id, &$form) {
  global $user;
  if ($form_id == 'user_edit') {

    //access check
    if (user_access('delete own account') && $form['_account']['#value']->uid == $user->uid) {
      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delete'),
        '#weight' => 31,
      );
    }
  }
  if ($form_id == 'user_confirm_delete') {
    $description = '';
    $default_op = variable_get('user_delete_default_action', 0);
    if ($default_op) {
      switch ($default_op) {
        case 'user_delete_block':
          $description = t('The account will be disabled, all submitted content will be kept.');
          break;
        case 'user_delete_block_unpublish':
          $description = t('The account will be disabled, all submitted content will be unpublished.');
          break;
        case 'user_delete_reassign':
          $description = t('The account will be deleted, all submitted content will be reassigned to the <em>Anonymous user</em>. This action cannot be undone.');
          break;
        case 'user_delete_delete':
          $description = t('The account and all submitted content will be deleted. This action cannot be undone.');
          break;
      }
      $form['description'] = array(
        '#value' => $description,
        '#weight' => -10,
      );
    }
    if (variable_get('user_delete_backup', 0)) {
      $form['user_delete_remark'] = array(
        '#value' => t('All data that is being deleted will be backed up for %period and automatically deleted afterwards.', array(
          '%period' => format_interval(variable_get('user_delete_backup_period', 60 * 60 * 24 * 7 * 12), 2),
        )),
        '#weight' => 0,
      );
    }
    if (!variable_get('user_delete_default_action', 0)) {
      $form['user_delete_action'] = array(
        '#type' => 'radios',
        '#title' => t('When deleting the account'),
        '#default_value' => 'user_delete_block',
        '#options' => array(
          'user_delete_block' => t('Disable the account and keep all content.'),
          'user_delete_block_unpublish' => t('Disable the account and unpublish all content.'),
          'user_delete_reassign' => t('Delete the account and make all content belong to the <em>Anonymous user</em>.'),
          'user_delete_delete' => t('Delete the account and all content.'),
        ),
        '#weight' => 0,
      );
    }
    $form['#redirect'] = 'user/' . $form['uid']['#value'];
    $form['#submit'] = array(
      'user_delete_submit' => array(),
    );
  }
}