You are here

protected function CheckoutFlowBase::actions in Commerce Core 8.2

Builds the actions element for the current form.

Parameters

array $form: The current form.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

Return value

array The actions element.

1 call to CheckoutFlowBase::actions()
CheckoutFlowBase::buildForm in modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php
Form constructor.

File

modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php, line 459

Class

CheckoutFlowBase
Provides the base checkout flow class.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $steps = $this
    ->getSteps();
  $next_step_id = $this
    ->getNextStepId($form['#step_id']);
  $previous_step_id = $this
    ->getPreviousStepId($form['#step_id']);
  $has_next_step = $next_step_id && isset($steps[$next_step_id]['next_label']);
  $has_previous_step = $previous_step_id && isset($steps[$previous_step_id]['previous_label']);
  $actions = [
    '#type' => 'actions',
    '#access' => $has_next_step,
  ];
  if ($has_next_step) {
    $actions['next'] = [
      '#type' => 'submit',
      '#value' => $steps[$next_step_id]['next_label'],
      '#button_type' => 'primary',
      '#submit' => [
        '::submitForm',
      ],
    ];
    if ($has_previous_step) {
      $label = $steps[$previous_step_id]['previous_label'];
      $options = [
        'attributes' => [
          'class' => [
            'link--previous',
          ],
        ],
      ];
      $actions['next']['#suffix'] = Link::createFromRoute($label, 'commerce_checkout.form', [
        'commerce_order' => $this->order
          ->id(),
        'step' => $previous_step_id,
      ], $options)
        ->toString();
    }
  }
  return $actions;
}