function RegisterForm::submitForm
Same name and namespace in other branches
- 11.x core/modules/user/src/RegisterForm.php \Drupal\user\RegisterForm::submitForm()
- 10 core/modules/user/src/RegisterForm.php \Drupal\user\RegisterForm::submitForm()
- 9 core/modules/user/src/RegisterForm.php \Drupal\user\RegisterForm::submitForm()
- 8.9.x core/modules/user/src/RegisterForm.php \Drupal\user\RegisterForm::submitForm()
Overrides AccountForm::submitForm
File
-
core/
modules/ user/ src/ RegisterForm.php, line 64
Class
- RegisterForm
- Form handler for the user register forms.
Namespace
Drupal\userCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$admin = $form_state->getValue('administer_users');
$notify = !$form_state->isValueEmpty('notify');
// Use the submitted password only when the password field is accessible:
// either self-registration with email verification disabled, or admin
// creation without the notification checkbox. In all other cases, generate
// a random password so the user must set their own via email.
if ($admin && !$notify || !\Drupal::config('user.settings')->get('verify_mail')) {
$pass = $form_state->getValue('pass');
}
else {
$pass = \Drupal::service('password_generator')->generate();
}
// Remove unneeded values.
$form_state->cleanValues();
$form_state->setValue('pass', $pass);
$form_state->setValue('init', $form_state->getValue('mail'));
parent::submitForm($form, $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.