function FormStatePersistTest::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/ src/ Kernel/ Form/ FormStatePersistTest.php, line 49
Class
- FormStatePersistTest
- Tests that the form state persists across multiple requests.
Namespace
Drupal\Tests\system\Kernel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
$form['title'] = [
'#type' => 'textfield',
'#title' => 'title',
'#default_value' => 'DEFAULT',
'#required' => TRUE,
];
// Set a flag in form state storage during build, so this can be confirmed
// in test assertions.
$form_state->set('build', TRUE);
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
$form['#process'][] = [
static::class,
'setStateRebuildValue',
];
$form['#post_render'][] = [
static::class,
'displayCachedState',
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.