Same name and namespace in other branches
- 8.9.x core/modules/system/tests/modules/form_test/src/FormTestObject.php \Drupal\form_test\FormTestObject
- 9 core/modules/system/tests/modules/form_test/src/FormTestObject.php \Drupal\form_test\FormTestObject
Provides a test form object.
@internal
Hierarchy
- class \Drupal\form_test\FormTestObject extends \Drupal\Core\Form\ConfigFormBase
Expanded class hierarchy of FormTestObject
1 file declares its use of FormTestObject
- FormObjectTest.php in core/
modules/ system/ tests/ src/ Kernel/ Form/ FormObjectTest.php
1 string reference to 'FormTestObject'
- form_test.routing.yml in core/
modules/ system/ tests/ modules/ form_test/ form_test.routing.yml - core/modules/system/tests/modules/form_test/form_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ form_test/ src/ FormTestObject.php, line 13
Namespace
Drupal\form_testView source
class FormTestObject extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_form_test_object';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'form_test.object',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['element'] = [
'#markup' => 'The FormTestObject::buildForm() method was used for this form.',
];
$form['bananas'] = [
'#type' => 'textfield',
'#title' => $this
->t('Bananas'),
];
$form['strawberry'] = [
'#type' => 'hidden',
'#value' => 'red',
'#attributes' => [
'id' => 'red-strawberry-hidden-field',
],
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
$form['#title'] = 'Test dynamic title';
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus($this
->t('The FormTestObject::validateForm() method was used for this form.'));
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus($this
->t('The FormTestObject::submitForm() method was used for this form.'));
$this
->config('form_test.object')
->set('bananas', $form_state
->getValue('bananas'))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormTestObject:: |
public | function | ||
FormTestObject:: |
protected | function | ||
FormTestObject:: |
public | function | ||
FormTestObject:: |
public | function | ||
FormTestObject:: |
public | function |