public function UserCancelForm::submitForm in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/src/Form/UserCancelForm.php \Drupal\user\Form\UserCancelForm::submitForm()
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ContentEntityForm::submitForm
File
- core/
modules/ user/ src/ Form/ UserCancelForm.php, line 138
Class
- UserCancelForm
- Provides a confirmation form for cancelling user account.
Namespace
Drupal\user\FormCode
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')
->notice('Sent account cancellation request to %name %email.', [
'%name' => $this->entity
->label(),
'%email' => '<' . $this->entity
->getEmail() . '>',
]);
$form_state
->setRedirect('entity.user.canonical', [
'user' => $this->entity
->id(),
]);
}
}