diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index 3e1885a..df48f23 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -90,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($form_state->getValue('step') == 1) { $form['name'] = array( '#type' => 'textfield', - '#title' => t('Username or e-mail address'), + '#title' => t('Username or email address'), '#size' => 60, '#maxlength' => max(USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH), '#required' => TRUE, @@ -103,15 +103,16 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); // Allow logged in users to request this also. $user = $this->currentUser(); - if ($user->id() > 0) { + if ($user->isAuthenticated()) { $form['name']['#type'] = 'value'; $form['name']['#value'] = $user->getEmail(); $form['mail'] = array( '#prefix' => '
', - '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())), + '#markup' => $this->t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())), '#suffix' => '
', ); } + $form['name']['#default_value'] = $this->getRequest()->query->get('name'); } else { // Where there is a conflict between the username and email address for two @@ -119,9 +120,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { $accounts = $form_state->getStorage()['accounts']; $options = array(); foreach ($accounts as $account) { - $label = t('The account with the username: @name', array('@name' => $account->getUsername())); - if ($account->getEmail() == $form_state->getStorage()['name']) { - $label = t('The account with the email address: @email', array('@email' => $account->getEmail())); + $label = $this->t('The account with the username: @name', array('@name' => $account->getUsername())); + if ($account->getEmail() === $form_state->getStorage()['name']) { + $label = $this->t('The account with the email address: @email', array('@email' => $account->getEmail())); } $options[Crypt::hashBase64(Settings::getHashSalt() . $account->id())] = $label; } @@ -129,7 +130,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'radios', '#title' => t('Choose account'), '#required' => TRUE, - '#prefix' => "" . t("There is a username conflict with the email address @email. Please select which account password to reset.", array('@email' => $form_state->getStorage()['name'])) . "
", + '#prefix' => "" . $this->t("There is a username conflict with the email address @email. Please select which account password to reset.", array('@email' => $form_state->getStorage()['name'])) . "
", '#options' => $options, '#default_value' => Crypt::hashBase64(Settings::getHashSalt() . reset($accounts)->id()), ); @@ -138,13 +139,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'hidden', '#value' => 2, ); - $form['name']['#default_value'] = $this->getRequest()->query->get('name'); } $form['actions'] = array('#type' => 'actions'); if ($form_state->getValue('step') == 2) { $form['actions']['cancel'] = array( '#type' => 'submit', - '#value' => t('Cancel'), + '#value' => $this->t('Cancel'), '#name' => 'cancel', '#limit_validation_errors' => array(), '#weight' => 5, @@ -152,7 +152,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), '#name' => 'submit' ); @@ -192,7 +192,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $form_state->setValue('accounts', $accounts); } else { - $form_state->setErrorByName('name', t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); + $form_state->setErrorByName('name', $this->t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); } } else if ($form_state->getValue('step') == 2) { @@ -239,7 +239,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $mail = _user_mail_notify('password_reset', $account, $language_interface->getId()); if (!empty($mail)) { \Drupal::logger('user')->notice('Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail)); - drupal_set_message(t('Further instructions have been sent to your e-mail address.')); + drupal_set_message($this->t('Further instructions have been sent to your e-mail address.')); } $form_state->setRedirectUrl(Url::fromRoute('user.page')); diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php index af56e30..d8e98d2 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/src/Tests/UserPasswordResetTest.php @@ -136,7 +136,7 @@ function testUserPasswordReset() { $edit = array('name' => $this->randomMachineName(32)); $this->drupalPostForm(NULL, $edit, t('Submit')); - $this->assertRaw(t('Sorry, %name is not recognized as a username or an email address.', array('%name' => $edit['name'])), 'Validation error message shown when trying to request password for invalid account.'); + $this->assertRaw(t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $edit['name'])), 'Validation error message shown when trying to request password for invalid account.'); $this->assertEqual(count($this->drupalGetMails(array('id' => 'user_password_reset'))), 0, 'No email was sent when requesting a password for an invalid account.'); // Reset the password by username via the password reset page.