public function DimensionsTestForm::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/ DimensionsTestForm.php, line 22
Class
Namespace
Drupal\physical_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $restrict_unit = FALSE) {
$form['dimensions'] = [
'#type' => 'physical_dimensions',
'#title' => $this
->t('Dimensions'),
'#default_value' => [
'length' => '1.92',
'width' => '2.5',
'height' => '2.1',
'unit' => LengthUnit::METER,
],
'#required' => TRUE,
];
if ($restrict_unit) {
$form['dimensions']['#available_units'] = [
LengthUnit::METER,
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}