public function SocialUserLoginForm::buildForm in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.2 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.3 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.4 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.5 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.7 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 8.8 modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 10.3.x modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 10.0.x modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 10.1.x modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
- 10.2.x modules/social_features/social_user/src/Form/SocialUserLoginForm.php \Drupal\social_user\Form\SocialUserLoginForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides UserLoginForm::buildForm
File
- modules/
social_features/ social_user/ src/ Form/ SocialUserLoginForm.php, line 34
Class
- SocialUserLoginForm
- Class SocialUserLoginForm.
Namespace
Drupal\social_user\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('system.site');
// We create a fieldset for the default username login.
$form['username_login'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Log in with <b>username</b> or <b>email</b>'),
];
// If we have a help text then we display it to the user.
$login_help = \Drupal::config('social_user.settings')
->get('login_help');
if (!empty($login_help)) {
$form['username_login']['#description'] = $login_help;
}
// Display login form:
$form['username_login']['name_or_mail'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username or email address'),
'#size' => 60,
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => $this
->t('Enter your @s username or email.', [
'@s' => $config
->get('name'),
]),
'#required' => TRUE,
'#attributes' => [
'autocorrect' => 'none',
'autocapitalize' => 'none',
'spellcheck' => 'false',
'autofocus' => 'autofocus',
],
];
$reset_pass_link = Link::createFromRoute($this
->t('Forgot password?'), 'user.pass');
$generated_reset_pass_link = $reset_pass_link
->toString();
$pass_description = $generated_reset_pass_link
->getGeneratedLink();
$form['username_login']['pass'] = [
'#type' => 'password',
'#title' => $this
->t('Password'),
'#size' => 60,
'#description' => $pass_description,
'#required' => TRUE,
];
$link_options = [];
// Preserve the destination parameter when a user logs in instead.
$request = \Drupal::request();
if ($request->query
->has('destination')) {
$link_options['query'] = [
'destination' => $request->query
->get('destination'),
];
}
if (\Drupal::config('user.settings')
->get('register') != 'admin_only') {
$sign_up_link = Link::createFromRoute($this
->t('Sign up'), 'user.register', [], $link_options)
->toString();
$form['username_login']['sign-up-link'] = [
'#markup' => $this
->t("Don't have an account yet? @link", [
"@link" => $sign_up_link,
]),
'#weight' => 1000,
'#cache' => [
'contexts' => [
'url.query_args',
],
],
];
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Log in'),
];
// Validates account and sets the form state uid that is used in the
// submit function.
$form['#validate'][] = '::validateAuthentication';
// Validates if the uid is set and display an error message if the input
// is invalid.
// Validates if a user with a username or email is blocked.
$form['#validate'][] = '::validateNameMail';
$form['#validate'][] = '::validateFinal';
$this->renderer
->addCacheableDependency($form, $config);
return $form;
}