How to cancel user accounts without e-mail confirmation? I want to allow users to cancel their accounts immediately instead of having to confirm the cancellation by email (because users forget passwords, lose access to email, and other problems).

There is a great answer to the Drupal 7 version of this question and it inspired a module.

So I attempted to adopt the code in the module for Drupal 8.

First, though, you need to prevent the "account cancellation confirmation email from being sent; otherwise, users will receive an email to click a link when they don't need to.

You can do this as follows:


drush cex
Edit user.settings.yml
Change cancel_confirm to false
drush cim


Here is my code with a problem:

function MYMODULE_form_user_cancel_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['#submit'][] = 'mymodule_user_cancel_form_submit';
}

function MYMODULE_user_cancel_form_submit(&amp;$form, &amp;$form_state) {
  $uid = $form['uid']['#value'];
  $user = \Drupal::currentUser();
  if (!$user-&gt;hasPermission('administer users') &amp;&amp; $uid == $user-&gt;id()) {    
    // Hide "A confirmation request to cancel your account has been sent to your email address."
    $messages = drupal_get_messages('status', FALSE);
    if (!empty($messages['status'])) {
      unset($_SESSION['messages']['status']);
    }

    // Cancel the account, from user_cancel_confirm()
    user_cancel($form_state-&gt;getValues(), $uid, $form_state-&gt;getValue('user_cancel_method'));    

    // Since user_cancel() is not invoked via Form API, batch processing needs
    // to be invoked manually and will redirect to the front page after
    // completion.
    batch_process('');

  }
}


The main problem is that after calling the submit callback, I get the message "The update has been performed.", but the user account is not cancelled.

I used kint() to debug and the submit callback is evaluated and user_cancel is called, but the account is not actually blocked.  Users do have permission to cancel their own accounts.
Please use this code snippet it works for me 

 function simple_pass_reset_form_user_cancel_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  //  dsm($form);
  $form['actions']['submit']['#submit'][] = 'simple_pass_reset_user_cancel_form_submit';
}

function simple_pass_reset_user_cancel_form_submit(&amp;$form, &amp;$form_state) {
  $uid = $form['uid']['#value'];
  // exit;
  $user = \Drupal::currentUser();
  if (!$user-&gt;hasPermission('administer users') &amp;&amp; $uid == $user-&gt;id()) {
    // Hide "A confirmation request to cancel your account has been sent to your email address."
    $messages = drupal_get_messages('status', FALSE);
    if (!empty($messages['status'])) {
      unset($_SESSION['messages']['status']);
    }

    // Cancel the account, from user_cancel_confirm()
    user_cancel($form_state-&gt;getValues(), $uid, $form_state-&gt;getValue('user_cancel_method'));

    // Since user_cancel() is not invoked via Form API, batch processing needs
    // to be invoked manually and will redirect to the front page after
    // completion.
//You need to run batch process
    $batch = &amp;batch_get();
    $batch['progressive'] = FALSE;
    batch_process('');
  }
}