You are here

public function AjaxAttachTrait::ajaxReplaceCheckoutPane in Ubercart 8.4

Ajax callback to replace a whole checkout pane.

Parameters

array $form: The checkout form.

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

$wrapper: Special third parameter passed for uc_ajax callbacks containing the ajax wrapper for this callback. Here used to determine which pane to replace.

Return value

array|null The form element representing the pane, suitable for ajax rendering. If the pane does not exist, or if the wrapper does not refer to a checkout pane, returns nothing.

File

uc_store/src/AjaxAttachTrait.php, line 216

Class

AjaxAttachTrait
Helper functions for ajax behaviors on the checkout and order-edit forms.

Namespace

Drupal\uc_store

Code

public function ajaxReplaceCheckoutPane(array $form, FormStateInterface $form_state, $wrapper = NULL) {
  $response = new AjaxResponse();
  $element = $form_state
    ->getTriggeringElement();
  if (empty($wrapper) && !empty($element['#ajax']['wrapper'])) {

    // If $wrapper is absent, then we were not invoked by ajaxMultiplex(),
    // so try to use the wrapper of the triggering element's #ajax array.
    $wrapper = $element['#ajax']['wrapper'];
  }
  if (!empty($wrapper)) {
    list($pane, $verify) = explode('-', $wrapper);
    if ($verify === 'pane' && !empty($form['panes'][$pane])) {

      // Replace the corresponding pane.
      $response
        ->addCommand(new ReplaceCommand('#' . $wrapper, $form['panes'][$pane]));
      return $response;
    }
  }
}