You are here

public function AjaxAdminForm::buildForm in Ubercart 8.4

Parameters

string $target_form: The form for which ajax behaviors are to be administered. Currently only 'checkout' is supported.

Overrides FormInterface::buildForm

File

uc_ajax_admin/src/Form/AjaxAdminForm.php, line 58

Class

AjaxAdminForm
Configures Ajax behaviours on the Ubercart checkout page.

Namespace

Drupal\uc_ajax_admin\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $target_form = 'checkout') {
  switch ($target_form) {
    case 'checkout':
      $triggers = _uc_ajax_admin_checkout_trigger_options(_uc_ajax_admin_build_checkout_form());
      $panes = $this->checkoutPaneManager
        ->getDefinitions();
      $wrappers = [];
      foreach ($panes as $id => $pane) {
        $wrappers["{$id}-pane"] = $pane['title'];
      }
      break;
    default:
      throw new NotFoundHttpException();
  }
  $form['#uc_ajax_target'] = $target_form;
  $form['#uc_ajax_config'] = $this
    ->config('uc_cart.settings')
    ->get('ajax.' . $target_form) ?: [];
  $form['table'] = uc_ajax_admin_table($triggers, $wrappers, $form['#uc_ajax_config']);
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Submit'),
    ],
  ];
  return $form;
}