You are here

public function MeasurementTestForm::buildForm in Physical Fields 8

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

tests/modules/physical_test/src/Form/MeasurementTestForm.php, line 22

Class

MeasurementTestForm

Namespace

Drupal\physical_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $restrict_unit = FALSE) {
  $form['height'] = [
    '#type' => 'physical_measurement',
    '#measurement_type' => 'length',
    '#title' => $this
      ->t('Height'),
    '#default_value' => [
      'number' => '1.92',
      'unit' => LengthUnit::METER,
    ],
    '#required' => TRUE,
  ];
  if ($restrict_unit) {
    $form['height']['#available_units'] = [
      LengthUnit::METER,
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}