_user_cancel($edit, $account, $method)
Implements callback_batch_operation().
Last step for cancelling a user account.
Since batch and session API require a valid user account, the actual cancellation of a user account needs to happen last.
Parameters
array $edit: An array of submitted form values.
\Drupal\user\UserInterface $account: The user ID of the user account to cancel.
string $method: The account cancellation method to use.
See also
File
- core/modules/user/user.module, line 731
- Enables the user registration and login system.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function _user_cancel( $edit , $account , $method ) { $logger = \Drupal::logger( 'user' ); switch ( $method ) { case 'user_cancel_block' : case 'user_cancel_block_unpublish' : default : // Send account blocked notification if option was checked. if (! empty ( $edit [ 'user_cancel_notify' ])) { _user_mail_notify( 'status_blocked' , $account ); } $account ->block(); $account ->save(); drupal_set_message(t( '%name has been disabled.' , array ( '%name' => $account ->getDisplayName()))); $logger ->notice( 'Blocked user: %name %email.' , array ( '%name' => $account ->getAccountName(), '%email' => '<' . $account ->getEmail() . '>' )); break ; case 'user_cancel_reassign' : case 'user_cancel_delete' : // Send account canceled notification if option was checked. if (! empty ( $edit [ 'user_cancel_notify' ])) { _user_mail_notify( 'status_canceled' , $account ); } $account -> delete (); drupal_set_message(t( '%name has been deleted.' , array ( '%name' => $account ->getDisplayName()))); $logger ->notice( 'Deleted user: %name %email.' , array ( '%name' => $account ->getAccountName(), '%email' => '<' . $account ->getEmail() . '>' )); break ; } // After cancelling account, ensure that user is logged out. We can't destroy // their session though, as we might have information in it, and we can't // regenerate it because batch API uses the session ID, we will regenerate it // in _user_cancel_session_regenerate(). if ( $account ->id() == \Drupal::currentUser()->id()) { \Drupal::currentUser()->setAccount( new AnonymousUserSession()); } } |
Please login to continue.