You are here

public function CheckoutFlowWithPanesBase::buildForm in Commerce Core 8.2

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 CheckoutFlowBase::buildForm

File

modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php, line 530

Class

CheckoutFlowWithPanesBase
Provides a base checkout flow that uses checkout panes.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

public function buildForm(array $form, FormStateInterface $form_state, $step_id = NULL) {
  $form = parent::buildForm($form, $form_state, $step_id);
  foreach ($this
    ->getVisiblePanes($step_id) as $pane_id => $pane) {
    $form[$pane_id] = [
      // Workaround for core bug #2897377.
      '#id' => Html::getId('edit-' . $pane_id),
      '#parents' => [
        $pane_id,
      ],
      '#theme' => 'commerce_checkout_pane',
      '#type' => $pane
        ->getWrapperElement(),
      '#title' => $pane
        ->getDisplayLabel(),
      '#attributes' => [
        'class' => [
          'checkout-pane',
          'checkout-pane-' . str_replace('_', '-', $pane_id),
        ],
      ],
      '#pane_id' => $pane_id,
    ];
    $form[$pane_id] = $pane
      ->buildPaneForm($form[$pane_id], $form_state, $form);

    // Avoid rendering an empty container.
    $form[$pane_id]['#access'] = (bool) Element::getVisibleChildren($form[$pane_id]);
  }
  if ($this
    ->hasSidebar($step_id)) {

    // The base class adds a hardcoded order summary view to the sidebar.
    // Remove it, there's a pane for that.
    unset($form['sidebar']);
    foreach ($this
      ->getVisiblePanes('_sidebar') as $pane_id => $pane) {
      $form['sidebar'][$pane_id] = [
        // Workaround for core bug #2897377.
        '#id' => Html::getId('edit-' . $pane_id),
        '#parents' => [
          'sidebar',
          $pane_id,
        ],
        '#type' => $pane
          ->getWrapperElement(),
        '#title' => $pane
          ->getDisplayLabel(),
        '#attributes' => [
          'class' => [
            'checkout-pane',
            'checkout-pane-' . str_replace('_', '-', $pane_id),
          ],
        ],
      ];
      $form['sidebar'][$pane_id] = $pane
        ->buildPaneForm($form['sidebar'][$pane_id], $form_state, $form);
    }
  }
  return $form;
}