You are here

public function QuotePane::view in Ubercart 8.4

Returns the contents of a checkout pane.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that is being processed.

array $form: The checkout form array.

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

Return value

array A form array, with an optional '#description' key to provide help text for the pane.

Overrides CheckoutPanePluginInterface::view

File

shipping/uc_quote/src/Plugin/Ubercart/CheckoutPane/QuotePane.php, line 25

Class

QuotePane
Shipping quote checkout pane plugin.

Namespace

Drupal\uc_quote\Plugin\Ubercart\CheckoutPane

Code

public function view(OrderInterface $order, array $form, FormStateInterface $form_state) {
  $contents['#description'] = $this
    ->t('Shipping quotes are generated automatically when you enter your address and may be updated manually with the button below.');
  $contents['#attached']['library'][] = 'uc_quote/uc_quote.styles';
  $contents['uid'] = [
    '#type' => 'hidden',
    '#value' => \Drupal::currentUser()
      ->id(),
  ];
  $contents['quote_button'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Click to calculate shipping'),
    '#submit' => [
      [
        $this,
        'paneSubmit',
      ],
    ],
    '#weight' => 0,
    '#ajax' => [
      'effect' => 'slide',
      'progress' => [
        'type' => 'bar',
        'message' => $this
          ->t('Receiving quotes...'),
      ],
    ],
    // Shipping quotes can be retrieved even if the form doesn't validate.
    '#limit_validation_errors' => [],
  ];
  $contents['quotes'] = [
    '#type' => 'container',
    '#attributes' => [
      'id' => 'quote',
    ],
    '#tree' => TRUE,
    '#weight' => 1,
  ];

  // If this was an Ajax request, we reinvoke the 'prepare' op to ensure
  // that we catch any changes in panes heavier than this one.
  if ($form_state
    ->getTriggeringElement()) {
    $this
      ->prepare($order, $form, $form_state);
  }
  $contents['quotes'] += $order->quote_form;
  $form_state
    ->set([
    'uc_ajax',
    'uc_quote',
    'panes][quotes][quote_button',
  ], [
    'payment-pane' => '::ajaxReplaceCheckoutPane',
    'quotes-pane' => '::ajaxReplaceCheckoutPane',
  ]);
  $form_state
    ->set([
    'uc_ajax',
    'uc_quote',
    'panes][quotes][quotes][quote_option',
  ], [
    'payment-pane' => '::ajaxReplaceCheckoutPane',
  ]);
  return $contents;
}