function ComponentAsFormElementTest::buildForm
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentAsFormElementTest.php, line 45
Class
- ComponentAsFormElementTest
- Tests the correct rendering of components in form.
Namespace
Drupal\KernelTests\ComponentsCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
$form['sdc_input'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
];
$form['sdc_input_basic'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#default_value' => 'test_data_default_value_basic',
];
$form['sdc_input_with_label'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#slots' => [
'label' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => [
'id' => 'test_data_label_container',
],
'content' => [
'#markup' => 'test_data_label',
],
],
],
];
$form['sdc_input_with_default_value'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#default_value' => 'test_data_default_value',
];
$form['sdc_input_with_value'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#value' => 'test_data_value',
];
$form['sdc_input_with_value_and_default_value'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#default_value' => 'test_data_default_value',
'#value' => 'test_data_value',
];
$form['sdc_input_with_required'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#required' => TRUE,
];
$form['sdc_input_with_id_as_prop'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#props' => [
'id' => 'test_sdc_input_prop_id',
],
];
$form['sdc_input_with_id_as_prop_attributes'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#props' => [
'attributes' => new Attribute([
'id' => 'test_sdc_input_prop_attributes_id',
]),
],
];
$form['sdc_input_with_validation'] = [
'#type' => 'component',
'#component' => 'sdc_theme_test:input',
'#default_value' => 'test_data_valid_value',
'#element_validate' => [
[
$this,
'customValidator',
],
],
];
$form['actions'] = [
'#type' => 'actions',
'submit' => [
'#type' => 'submit',
'#value' => 'Submit',
],
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.