UserPasswordForm::buildForm

public UserPasswordForm::buildForm(array $form, FormStateInterface $form_state)

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Overrides FormInterface::buildForm

File

core/modules/user/src/Form/UserPasswordForm.php, line 67

Class

UserPasswordForm
Provides a user password reset form.

Namespace

Drupal\user\Form

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public function buildForm(array $form, FormStateInterface $form_state) {
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => $this->t('Username or email address'),
    '#size' => 60,
    '#maxlength' => max(USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH),
    '#required' => TRUE,
    '#attributes' => array(
      'autocorrect' => 'off',
      'autocapitalize' => 'off',
      'spellcheck' => 'false',
      'autofocus' => 'autofocus',
    ),
  );
  // Allow logged in users to request this also.
  $user = $this->currentUser();
  if ($user->isAuthenticated()) {
    $form['name']['#type'] = 'value';
    $form['name']['#value'] = $user->getEmail();
    $form['mail'] = array(
      '#prefix' => '<p>',
      '#markup' => $this->t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the email.', array('%email' => $user->getEmail())),
      '#suffix' => '</p>',
    );
  }
  else {
    $form['mail'] = array(
      '#prefix' => '<p>',
      '#markup' => $this->t('Password reset instructions will be sent to your registered email address.'),
      '#suffix' => '</p>',
    );
    $form['name']['#default_value'] = $this->getRequest()->query->get('name');
  }
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit'));
 
  return $form;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.