You are here

public function AddToCartForm::buildForm in Ubercart 8.4

Form constructor.

Parameters

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 The form structure.

Overrides BuyItNowForm::buildForm

File

uc_product/src/Form/AddToCartForm.php, line 45

Class

AddToCartForm
Defines a complex form for adding a product to the cart.

Namespace

Drupal\uc_product\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
  $form = parent::buildForm($form, $form_state, $node);
  $form['node'] = [
    '#type' => 'value',
    '#value' => $form_state
      ->get('variant') ?: $node,
  ];
  if ($node->default_qty->value > 0) {
    if ($this
      ->config('uc_product.settings')
      ->get('add_to_cart_qty')) {
      $form['qty'] = [
        '#type' => 'uc_quantity',
        '#title' => $this
          ->t('Quantity'),
        '#default_value' => $node->default_qty->value,
      ];
    }
    else {
      $form['qty']['#value'] = $node->default_qty->value;
    }
  }
  return $form;
}