commerce-8.x-2.8/modules/price/tests/modules/commerce_price_test/src/Form/NumberTestForm.php

modules/price/tests/modules/commerce_price_test/src/Form/NumberTestForm.php
<?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'),
    ]));
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc