function _user_registrationpassword_user_pass_submit in User registration password 8
Same name and namespace in other branches
- 7 user_registrationpassword.module \_user_registrationpassword_user_pass_submit()
Implements submit function.
1 string reference to '_user_registrationpassword_user_pass_submit'
File
- ./
user_registrationpassword.module, line 481 - Enables password creation on registration form.
Code
function _user_registrationpassword_user_pass_submit(&$form, FormStateInterface $form_state) {
/** @var \Drupal\user\UserInterface $account */
$account = $form_state
->getValue('account');
// Then, if we have a user account
// and it has never ever been used.
if (!empty($account) && $account
->id() && !$account
->getLastLoginTime() && !$account
->getLastAccessedTime() && !$account
->isActive()) {
// Try to load the account in disabled state.
$users = \Drupal::entityQuery('user')
->condition('uid', $account
->id())
->condition('login', 0)
->condition('access', 0)
->condition('status', 0)
->execute();
$uid = reset($users);
// If the user never ever logged in, resend the activation mail.
if (!empty($uid)) {
/** @var \Drupal\user\UserInterface $account */
$account = \Drupal::entityTypeManager()
->getStorage('user')
->load($uid);
// Mail one time login URL and instructions using current language.
$mail = _user_registrationpassword_mail_notify('register_confirmation_with_pass', $account);
if (!empty($mail)) {
// And on success, log the email & throw a message.
\Drupal::logger('user')
->notice('Account confirmation mail sent via password reset form to %name at %email.', [
'%name' => $account
->getAccountName(),
'%email' => $account
->getEmail(),
]);
\Drupal::messenger()
->addMessage(t('Further instructions have been sent to your email address.'));
}
else {
// Or log the error.
\Drupal::logger('user')
->notice('Unable to send email. Contact the site administrator if the problem persists.');
}
}
}
else {
// If we found no errors execute core submission handler.
// Obviously cache is disabled on this pages, so this should work.
if (empty($_SESSION['messages']['error'])) {
$core_submit = new UserPasswordForm(\Drupal::entityTypeManager()
->getStorage('user'), \Drupal::languageManager(), \Drupal::configFactory(), \Drupal::flood());
$core_submit
->submitForm($form, $form_state);
}
}
}