public function Login::buildPaneForm in Commerce Core 8.2
Builds the pane form.
Parameters
array $pane_form: The pane form, containing the following basic properties:
- #parents: Identifies the position of the pane form in the overall parent form, and identifies the location where the field values are placed within $form_state->getValues().
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.
array $complete_form: The complete form structure.
Overrides CheckoutPaneInterface::buildPaneForm
File
- modules/
checkout/ src/ Plugin/ Commerce/ CheckoutPane/ Login.php, line 193
Class
- Login
- Provides the login pane.
Namespace
Drupal\commerce_checkout\Plugin\Commerce\CheckoutPaneCode
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form['#attached']['library'][] = 'commerce_checkout/login_pane';
$pane_form['returning_customer'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Returning Customer'),
'#attributes' => [
'class' => [
'form-wrapper__login-option',
'form-wrapper__returning-customer',
],
],
];
$pane_form['returning_customer']['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#size' => 60,
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
'#attributes' => [
'autocorrect' => 'none',
'autocapitalize' => 'none',
'spellcheck' => 'false',
'autofocus' => 'autofocus',
],
];
$pane_form['returning_customer']['password'] = [
'#type' => 'password',
'#title' => $this
->t('Password'),
'#size' => 60,
];
$pane_form['returning_customer']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Log in'),
'#op' => 'login',
'#attributes' => [
'formnovalidate' => 'formnovalidate',
],
'#limit_validation_errors' => [
array_merge($pane_form['#parents'], [
'returning_customer',
]),
],
'#submit' => [],
];
$pane_form['returning_customer']['forgot_password'] = [
'#type' => 'link',
'#title' => $this
->t('Forgot password?'),
'#url' => Url::fromRoute('user.pass'),
];
$pane_form['guest'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Guest Checkout'),
'#access' => $this->configuration['allow_guest_checkout'],
'#attributes' => [
'class' => [
'form-wrapper__login-option',
'form-wrapper__guest-checkout',
],
],
];
$pane_form['guest']['text'] = [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t('Proceed to checkout. You can optionally create an account at the end.'),
'#access' => $this
->canRegisterAfterCheckout(),
];
$pane_form['guest']['continue'] = [
'#type' => 'submit',
'#value' => $this
->t('Continue as Guest'),
'#op' => 'continue',
'#attributes' => [
'formnovalidate' => 'formnovalidate',
],
'#limit_validation_errors' => [],
'#submit' => [],
];
$pane_form['register'] = [
'#parents' => array_merge($pane_form['#parents'], [
'register',
]),
'#type' => 'fieldset',
'#title' => $this
->t('New Customer'),
'#access' => $this->configuration['allow_registration'],
'#attributes' => [
'class' => [
'form-wrapper__login-option',
'form-wrapper__guest-checkout',
],
],
];
$pane_form['register']['mail'] = [
'#type' => 'email',
'#title' => $this
->t('Email address'),
'#required' => FALSE,
];
$pane_form['register']['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
'#description' => $this
->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."),
'#required' => FALSE,
'#attributes' => [
'class' => [
'username',
],
'autocorrect' => 'off',
'autocapitalize' => 'off',
'spellcheck' => 'false',
],
'#default_value' => '',
];
$pane_form['register']['password'] = [
'#type' => 'password_confirm',
'#size' => 60,
'#description' => $this
->t('Provide a password for the new account in both fields.'),
'#required' => FALSE,
];
$pane_form['register']['register'] = [
'#type' => 'submit',
'#value' => $this
->t('Create account and continue'),
'#op' => 'register',
'#weight' => 50,
];
/** @var \Drupal\user\UserInterface $account */
$account = $this->entityTypeManager
->getStorage('user')
->create([]);
$form_display = EntityFormDisplay::collectRenderDisplay($account, 'register');
$form_display
->buildForm($account, $pane_form['register'], $form_state);
return $pane_form;
}