You are here

public function AjaxPriceTestForm::buildForm in Commerce Core 8.2

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

File

modules/price/tests/modules/commerce_price_test/src/Form/AjaxPriceTestForm.php, line 24

Class

AjaxPriceTestForm
A form for testing AJAX on commerce_price elements.

Namespace

Drupal\commerce_price_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['amount'] = [
    '#type' => 'commerce_price',
    '#title' => $this
      ->t('Amount'),
    '#default_value' => [
      'number' => '99.99',
      'currency_code' => 'USD',
    ],
    '#required' => TRUE,
    '#available_currencies' => [
      'USD',
      'EUR',
    ],
    '#ajax' => [
      'callback' => [
        $this,
        'ajaxSubmit',
      ],
      'wrapper' => 'ajax-replace',
    ],
  ];
  $form['ajax_info'] = [
    '#prefix' => '<div id="ajax-replace">',
    '#markup' => 'waiting',
    '#suffix' => '</div>',
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}