function FormTestLimitValidationErrorsForm::buildForm
Same name in other branches
- 8.9.x core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php \Drupal\form_test\Form\FormTestLimitValidationErrorsForm::buildForm()
- 10 core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php \Drupal\form_test\Form\FormTestLimitValidationErrorsForm::buildForm()
- 11.x core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php \Drupal\form_test\Form\FormTestLimitValidationErrorsForm::buildForm()
Overrides FormInterface::buildForm
File
-
core/
modules/ system/ tests/ modules/ form_test/ src/ Form/ FormTestLimitValidationErrorsForm.php, line 25
Class
- FormTestLimitValidationErrorsForm
- Builds a simple form with a button triggering partial validation.
Namespace
Drupal\form_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['title'] = [
'#type' => 'textfield',
'#title' => 'Title',
'#required' => TRUE,
];
$form['test'] = [
'#title' => 'Test',
'#type' => 'textfield',
'#element_validate' => [
'::elementValidateLimitValidationErrors',
],
];
$form['test_numeric_index'] = [
'#tree' => TRUE,
];
$form['test_numeric_index'][0] = [
'#title' => 'Test (numeric index)',
'#type' => 'textfield',
'#element_validate' => [
'::elementValidateLimitValidationErrors',
],
];
$form['test_substring'] = [
'#tree' => TRUE,
];
$form['test_substring']['foo'] = [
'#title' => 'Test (substring) foo',
'#type' => 'textfield',
'#element_validate' => [
'::elementValidateLimitValidationErrors',
],
];
$form['test_substring']['foobar'] = [
'#title' => 'Test (substring) foobar',
'#type' => 'textfield',
'#element_validate' => [
'::elementValidateLimitValidationErrors',
],
];
$form['actions']['partial'] = [
'#type' => 'submit',
'#limit_validation_errors' => [
[
'test',
],
],
'#submit' => [
'::partialSubmitForm',
],
'#value' => t('Partial validate'),
];
$form['actions']['partial_numeric_index'] = [
'#type' => 'submit',
'#limit_validation_errors' => [
[
'test_numeric_index',
0,
],
],
'#submit' => [
'::partialSubmitForm',
],
'#value' => t('Partial validate (numeric index)'),
];
$form['actions']['substring'] = [
'#type' => 'submit',
'#limit_validation_errors' => [
[
'test_substring',
'foo',
],
],
'#submit' => [
'::partialSubmitForm',
],
'#value' => t('Partial validate (substring)'),
];
$form['actions']['full'] = [
'#type' => 'submit',
'#value' => t('Full validate'),
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.