diff --git a/email_registration.module b/email_registration.module index 9e07937..2a131e8 100644 --- a/email_registration.module +++ b/email_registration.module @@ -9,7 +9,6 @@ use Drupal\user\UserInterface; use Drupal\Core\Render\Element\Email; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\Core\Link; /** * Implements hook_ENTITY_TYPE_insert(). @@ -184,8 +183,7 @@ function email_registration_user_login_validate($form, FormStateInterface $form_ elseif (!$config->get('login_with_username')) { $user_input = $form_state->getUserInput(); $query = isset($user_input['name']) ? ['name' => $user_input['name']] : []; - $link = Link::fromTextAndUrl(t('Forgot your password?'), Url::fromRoute('user.pass', [], ['query' => $query]))->toString(); - $form_state->setErrorByName('name', t('Unrecognized email address or password. :password', [':password' => $link])); + $form_state->setErrorByName('name', t('Unrecognized email address or password. Forgot your password?', [':password' => Url::fromRoute('user.pass', [], ['query' => $query])->toString()])); } } } diff --git a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php index 14a1760..a809f3a 100644 --- a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php +++ b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php @@ -14,7 +14,6 @@ use Drupal\user\UserAuthInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Drupal\Core\Config\ImmutableConfig; -use Drupal\Core\Link; /** * Provides the email registration login pane. @@ -119,8 +118,10 @@ class EmailRegistrationLogin extends Login { // bail out. $user_input = $form_state->getUserInput(); $query = isset($user_input[$subformId]['returning_customer']['name']) ? ['name' => $user_input[$subformId]['returning_customer']['name']] : []; - $link = Link::fromTextAndUrl($this->t('Forgot your password?'), Url::fromRoute('user.pass', [], ['query' => $query]))->toString(); - $form_state->setError($pane_form['returning_customer'], $this->t('Unrecognized email address or password. :password', [':password' => $link])); + $form_state->setError($pane_form['returning_customer'], $this->t('Unrecognized email address or password. Forgot your password?', [ + ':password' => Url::fromRoute('user.pass', [], ['query' => $query]) + ->toString(), + ])); return; } } @@ -140,7 +141,8 @@ class EmailRegistrationLogin extends Login { $password = trim($values['returning_customer']['password']); // Generate the "reset password" url. $query = !empty($username) ? ['name' => $username] : []; - $password_url = Url::fromRoute('user.pass', [], ['query' => $query]); + $password_url = Url::fromRoute('user.pass', [], ['query' => $query]) + ->toString(); if (user_is_blocked($username)) { $form_state->setError($name_element, $this->t('The account with email address %mail has not been activated or is blocked.', ['%mail' => $mail])); @@ -152,8 +154,7 @@ class EmailRegistrationLogin extends Login { $this->credentialsCheckFlood->register($this->clientIp, $username); // Changing the wrong credentials error message. if (!$this->config->get('login_with_username')) { - $link = Link::fromTextAndUrl($this->t('Forgot your password?'), $password_url)->toString(); - $form_state->setError($name_element, $this->t('Unrecognized email address or password. :password', [':password' => $link])); + $form_state->setError($name_element, $this->t('Unrecognized email address or password. Forgot your password?', [':password' => $password_url])); // Adding return to avoid the parent error when password is empty. return; } diff --git a/tests/src/Functional/EmailRegistrationTestCase.php b/tests/src/Functional/EmailRegistrationTestCase.php index e6fafb4..161fa96 100644 --- a/tests/src/Functional/EmailRegistrationTestCase.php +++ b/tests/src/Functional/EmailRegistrationTestCase.php @@ -20,6 +20,11 @@ class EmailRegistrationTestCase extends BrowserTestBase { */ public static $modules = ['email_registration']; + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * Test various behaviors for anonymous users. */ @@ -72,6 +77,8 @@ class EmailRegistrationTestCase extends BrowserTestBase { $this->assertSession()->responseContains('Enter your email address or username.'); $this->assertSession()->responseContains('Email or username'); $this->drupalPostForm('user/login', $login, 'Log in'); + // When login_with_username is true, a user can login with just their + // username. $this->assertSession()->responseContains('