function FormTestDetailsContainsRequiredFieldsForm::buildForm
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsContainsRequiredFieldsForm.php \Drupal\form_test\Form\FormTestDetailsContainsRequiredFieldsForm::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
-
core/
modules/ system/ tests/ modules/ form_test/ src/ Form/ FormTestDetailsContainsRequiredFieldsForm.php, line 27
Class
- FormTestDetailsContainsRequiredFieldsForm
- Builds a form to test required fields within details elements.
Namespace
Drupal\form_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $use_ajax = FALSE) : array {
$form['meta'] = [
'#type' => 'details',
'#title' => 'Details element',
'#open' => FALSE,
];
$form['meta']['required_textfield_in_details'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'Required textfield',
];
$form['meta2'] = [
'#type' => 'details',
'#title' => 'Details element 2',
'#open' => FALSE,
];
$form['meta2']['required_textarea_in_details'] = [
'#type' => 'textarea',
'#required' => TRUE,
'#title' => 'Required textarea',
];
$form['meta3'] = [
'#type' => 'details',
'#title' => 'Details element 3',
'#open' => FALSE,
];
$form['meta3']['required_select_in_details'] = [
'#type' => 'select',
'#options' => [
'one',
'two',
'three',
'four',
'five',
],
'#required' => TRUE,
'#title' => 'Required select',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
if ($use_ajax) {
$form['submitAjax'] = [
'#type' => 'submit',
'#value' => 'Submit Ajax',
'#ajax' => [
'callback' => '::submitForm',
'event' => 'click',
'wrapper' => 'form-test-details-form',
],
];
}
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.