function user_cancel_confirm_form

Form builder; confirm form for cancelling user account.

See also

user_edit_cancel_submit()

Related topics

1 string reference to 'user_cancel_confirm_form'
user_menu in modules/user/user.module
Implements hook_menu().

File

modules/user/user.pages.inc, line 476

Code

function user_cancel_confirm_form($form, &$form_state, $account) {
    global $user;
    $form['_account'] = array(
        '#type' => 'value',
        '#value' => $account,
    );
    // Display account cancellation method selection, if allowed.
    $admin_access = user_access('administer users');
    $can_select_method = $admin_access || user_access('select account cancellation method');
    $form['user_cancel_method'] = array(
        '#type' => 'item',
        '#title' => $account->uid == $user->uid ? t('When cancelling your account') : t('When cancelling the account'),
        '#access' => $can_select_method,
    );
    $form['user_cancel_method'] += user_cancel_methods();
    // Allow user administrators to skip the account cancellation confirmation
    // mail (by default), as long as they do not attempt to cancel their own
    // account.
    $override_access = $admin_access && $account->uid != $user->uid;
    $form['user_cancel_confirm'] = array(
        '#type' => 'checkbox',
        '#title' => t('Require e-mail confirmation to cancel account.'),
        '#default_value' => $override_access ? FALSE : TRUE,
        '#access' => $override_access,
        '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
    );
    // Also allow to send account canceled notification mail, if enabled.
    $default_notify = variable_get('user_mail_status_canceled_notify', FALSE);
    $form['user_cancel_notify'] = array(
        '#type' => 'checkbox',
        '#title' => t('Notify user when account is canceled.'),
        '#default_value' => $override_access ? FALSE : $default_notify,
        '#access' => $override_access && $default_notify,
        '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
    );
    // Prepare confirmation form page title and description.
    if ($account->uid == $user->uid) {
        $question = t('Are you sure you want to cancel your account?');
    }
    else {
        $question = t('Are you sure you want to cancel the account %name?', array(
            '%name' => $account->name,
        ));
    }
    $description = '';
    if ($can_select_method) {
        $description = t('Select the method to cancel the account above.');
        foreach (element_children($form['user_cancel_method']) as $element) {
            unset($form['user_cancel_method'][$element]['#description']);
        }
    }
    else {
        // The radio button #description is used as description for the confirmation
        // form.
        foreach (element_children($form['user_cancel_method']) as $element) {
            if ($form['user_cancel_method'][$element]['#default_value'] == $form['user_cancel_method'][$element]['#return_value']) {
                $description = $form['user_cancel_method'][$element]['#description'];
            }
            unset($form['user_cancel_method'][$element]['#description']);
        }
    }
    // Always provide entity id in the same form key as in the entity edit form.
    $form['uid'] = array(
        '#type' => 'value',
        '#value' => $account->uid,
    );
    return confirm_form($form, $question, 'user/' . $account->uid, $description . ' ' . t('This action cannot be undone.'), t('Cancel account'), t('Cancel'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.