/**
* {@inheritdoc}
*/
public function submitForm(array &
$form, FormStateInterface
$form_state) { // Cancel account immediately, if the current user has administrative
// privileges, no confirmation mail shall be sent, and the user does not
// attempt to cancel the own account.
if (!
$form_state->
isValueEmpty('access'
) &&
$form_state->
isValueEmpty('user_cancel_confirm'
) &&
$this->entity->
id() !=
$this->
currentUser()->
id()) { user_cancel($form_state->
getValues(),
$this->entity->
id(),
$form_state->
getValue('user_cancel_method'
));
$form_state->
setRedirectUrl($this->entity->
toUrl('collection'
));
} else { // Store cancelling method and whether to notify the user in
// $this->entity for
// \Drupal\user\Controller\UserController::confirmCancel().
$this->entity->user_cancel_method =
$form_state->
getValue('user_cancel_method'
);
$this->entity->user_cancel_notify =
$form_state->
getValue('user_cancel_notify'
);
$this->entity->
save();
_user_mail_notify('cancel_confirm',
$this->entity
);
$this->
messenger()->
addStatus($this->
t('A confirmation request to cancel your account has been sent to your email address.'
));
$this->
logger('user'
)->
info('Sent account cancellation request to %name %email.',
['%name' =>
$this->entity->
label(), '%email' => '<' .
$this->entity->
getEmail() . '>'
]);