You are here

public function BuyItNowForm::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 FormInterface::buildForm

1 call to BuyItNowForm::buildForm()
AddToCartForm::buildForm in uc_product/src/Form/AddToCartForm.php
Form constructor.
1 method overrides BuyItNowForm::buildForm()
AddToCartForm::buildForm in uc_product/src/Form/AddToCartForm.php
Form constructor.

File

uc_product/src/Form/BuyItNowForm.php, line 55

Class

BuyItNowForm
Defines a simple 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) {
  $query = $this
    ->getRequest()->query
    ->all();
  $form['#action'] = Url::fromRoute('<current>')
    ->setOptions([
    'query' => $query,
  ])
    ->toString();
  $form['nid'] = [
    '#type' => 'value',
    '#value' => $node
      ->id(),
  ];
  $form['node'] = [
    '#type' => 'value',
    '#value' => $node,
  ];
  $form['qty'] = [
    '#type' => 'value',
    '#value' => 1,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add to cart'),
  ];
  uc_form_alter($form, $form_state, $this
    ->getFormId());
  return $form;
}