You are here

protected function CheckoutFlowWithPanesBase::buildPaneRow in Commerce Core 8.2

Builds the table row structure for a checkout pane.

Parameters

\Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface $pane: The checkout pane.

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 A table row array.

1 call to CheckoutFlowWithPanesBase::buildPaneRow()
CheckoutFlowWithPanesBase::buildConfigurationForm in modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php
Form constructor.

File

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

Class

CheckoutFlowWithPanesBase
Provides a base checkout flow that uses checkout panes.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

protected function buildPaneRow(CheckoutPaneInterface $pane, array &$form, FormStateInterface $form_state) {
  $pane_id = $pane
    ->getPluginId();
  $label = $pane
    ->getLabel();
  $region_titles = array_map(function ($region) {
    return $region['title'];
  }, $this
    ->getTableRegions());
  $pane_row = [
    '#attributes' => [
      'class' => [
        'draggable',
        'tabledrag-leaf',
      ],
    ],
    'human_name' => [
      '#plain_text' => $label,
    ],
    'weight' => [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Weight for @title', [
        '@title' => $label,
      ]),
      '#title_display' => 'invisible',
      '#default_value' => $pane
        ->getWeight(),
      '#size' => 3,
      '#attributes' => [
        'class' => [
          'pane-weight',
        ],
      ],
    ],
    'step_wrapper' => [
      '#parents' => array_merge($form['#parents'], [
        'panes',
        $pane_id,
      ]),
      'step_id' => [
        '#type' => 'select',
        '#title' => $this
          ->t('Checkout step for @title', [
          '@title' => $label,
        ]),
        '#title_display' => 'invisible',
        '#options' => $region_titles,
        '#default_value' => $pane
          ->getStepId(),
        '#attributes' => [
          'class' => [
            'js-pane-step',
            'pane-step',
          ],
        ],
      ],
      'pane_id' => [
        '#type' => 'hidden',
        '#default_value' => $pane_id,
        '#attributes' => [
          'class' => [
            'pane-id',
          ],
        ],
      ],
    ],
  ];
  $base_button = [
    '#submit' => [
      [
        get_class($this),
        'multistepSubmit',
      ],
    ],
    '#ajax' => [
      'callback' => [
        get_class($this),
        'multistepAjax',
      ],
      'wrapper' => $form['panes']['#wrapper_id'],
    ],
    '#pane_id' => $pane_id,
  ];
  if ($form_state
    ->get('pane_configuration_edit') == $pane_id) {
    $pane_row['#attributes']['class'][] = 'pane-configuration-editing';
    $pane_row['configuration'] = [
      '#parents' => array_merge($form['#parents'], [
        'panes',
        $pane_id,
        'configuration',
      ]),
      '#type' => 'container',
      '#wrapper_attributes' => [
        'colspan' => 2,
      ],
      '#attributes' => [
        'class' => [
          'pane-configuration-edit-form',
        ],
      ],
      '#element_validate' => [
        [
          get_class($this),
          'validatePaneConfigurationForm',
        ],
      ],
      '#pane_id' => $pane_id,
    ];
    $pane_row['configuration'] = $pane
      ->buildConfigurationForm($pane_row['configuration'], $form_state);
    $pane_row['configuration']['actions'] = [
      '#type' => 'actions',
      'save' => $base_button + [
        '#type' => 'submit',
        '#button_type' => 'primary',
        '#name' => $pane_id . '_pane_configuration_update',
        '#value' => $this
          ->t('Update'),
        '#op' => 'update',
      ],
      'cancel' => $base_button + [
        '#type' => 'submit',
        '#name' => $pane_id . '_plugin_settings_cancel',
        '#value' => $this
          ->t('Cancel'),
        '#op' => 'cancel',
        '#limit_validation_errors' => [],
      ],
    ];
  }
  else {
    $pane_row['configuration_summary'] = [];
    $pane_row['configuration_edit'] = [];
    $summary = $pane
      ->buildConfigurationSummary();
    if (!empty($summary)) {
      $pane_row['configuration_summary'] = [
        '#markup' => $summary,
        '#prefix' => '<div class="pane-configuration-summary">',
        '#suffix' => '</div>',
        '#wrapper_attributes' => [
          'class' => [
            'pane-configuration-summary-cell',
          ],
        ],
      ];
    }

    // Check selected plugin settings to display edit link or not.
    $settings_form = $pane
      ->buildConfigurationForm([], $form_state);
    if (!empty($settings_form)) {
      $pane_row['configuration_edit'] = $base_button + [
        '#type' => 'image_button',
        '#name' => $pane_id . '_configuration_edit',
        '#src' => 'core/misc/icons/787878/cog.svg',
        '#attributes' => [
          'class' => [
            'pane-configuration-edit',
          ],
          'alt' => $this
            ->t('Edit'),
        ],
        '#op' => 'edit',
        '#limit_validation_errors' => [],
        '#prefix' => '<div class="pane-configuration-edit-wrapper">',
        '#suffix' => '</div>',
      ];
    }
  }
  return $pane_row;
}