You are here

public function CompletionRegister::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/CompletionRegister.php, line 169

Class

CompletionRegister
Provides the registration after checkout pane.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane

Code

public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
  $pane_form['#theme'] = 'commerce_checkout_completion_register';
  $pane_form['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['pass'] = [
    '#type' => 'password_confirm',
    '#size' => 60,
    '#description' => $this
      ->t('Provide a password for the new account.'),
    '#required' => TRUE,
  ];
  $pane_form['actions'] = [
    '#type' => 'actions',
  ];
  $pane_form['actions']['register'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Create account'),
    '#name' => 'checkout_completion_register',
  ];

  /** @var \Drupal\user\UserInterface $account */
  $account = $this->entityTypeManager
    ->getStorage('user')
    ->create([]);
  $form_display = EntityFormDisplay::collectRenderDisplay($account, 'register');
  $form_display
    ->buildForm($account, $pane_form, $form_state);
  return $pane_form;
}