public function DurationElementStatesTestForm::buildForm in Duration Field 3.0.x
Same name and namespace in other branches
- 8.2 tests/modules/duration_field_form_test/src/Form/DurationElementStatesTestForm.php \Drupal\duration_field_form_test\Form\DurationElementStatesTestForm::buildForm()
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/ duration_field_form_test/ src/ Form/ DurationElementStatesTestForm.php, line 23
Class
- DurationElementStatesTestForm
- Form for testing JavaScript #states behavior on 'duration' elements.
Namespace
Drupal\duration_field_form_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Trigger element.
$form['checkbox_trigger'] = [
'#type' => 'checkbox',
'#title' => 'Checkbox trigger',
];
// Duration elements that respond to the trigger.
$form['duration_invisible_when_checkbox_trigger_checked'] = [
'#type' => 'duration',
'#title' => 'Duration invisible when checkbox trigger checked',
'#states' => [
'invisible' => [
':input[name="checkbox_trigger"]' => [
'checked' => TRUE,
],
],
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
];
return $form;
}