function user_registrationpassword_form_user_register_submit in User registration password 8
Same name and namespace in other branches
- 6 user_registrationpassword.module \user_registrationpassword_form_user_register_submit()
- 7 user_registrationpassword.module \user_registrationpassword_form_user_register_submit()
Implements submission handler for the user registration form.
See also
user_register_form()
user_registrationpassword_form_user_register_form_alter()
2 string references to 'user_registrationpassword_form_user_register_submit'
- UserRegistrationPasswordUserRegisterForm::testUserRegisterFormCompatibility in ./
UserRegistrationPasswordUserRegisterForm.php - Implements testUserRegisterFormCompatibility().
- user_registrationpassword_form_user_register_form_alter in ./
user_registrationpassword.module - Implements hook_form_FORM_ID_alter().
File
- ./
user_registrationpassword.module, line 279 - Enables password creation on registration form.
Code
function user_registrationpassword_form_user_register_submit(&$form, FormStateInterface $form_state) {
// Define the message we need to remove.
// Yes, this throws a code style error, but this is in core.
// See user.module, that string contains a <br />.
$message = t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your email address.');
// Unset all messages that contain the $message.
$messenger = \Drupal::messenger();
// Cannot delete a single message, getting all and re-setting but the
// one from the core user register form.
foreach ($messenger
->deleteByType(MessengerInterface::TYPE_STATUS) as $statusmessage) {
if (!((string) $message == (string) $statusmessage)) {
$messenger
->addStatus($statusmessage);
}
}
// Notify the user.
/** @var \Drupal\user\UserInterface $account */
$account = $form_state
->getFormObject()
->getEntity();
// Send the confirmation email.
_user_registrationpassword_mail_notify('register_confirmation_with_pass', $account);
// Set success message and redirect to the front page.
\Drupal::messenger()
->addMessage(t('A welcome message with further instructions has been sent to your email address.'));
}