You are here

NumberTestForm.php in Commerce Core 8.2

File

modules/price/tests/modules/commerce_price_test/src/Form/NumberTestForm.php
View source
<?php

namespace Drupal\commerce_price_test\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class NumberTestForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'commerce_number_element_test_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['number'] = [
      '#type' => 'commerce_number',
      '#title' => $this
        ->t('Amount'),
      '#default_value' => '99.99',
      '#min' => 2,
      '#max' => 100,
      '#required' => TRUE,
    ];
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Submit'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->messenger()
      ->addMessage(t('The number is "@number".', [
      '@number' => $form_state
        ->getValue('number'),
    ]));
  }

}

Classes

Namesort descending Description
NumberTestForm