Same filename and directory in other branches
- 8.9.x core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php
- 9 core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php
Namespace
Drupal\form_test
File
core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php
View source
<?php
namespace Drupal\form_test;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class FormTestArgumentsObject extends ConfigFormBase {
public function getFormId() {
return 'form_test_form_test_arguments_object';
}
protected function getEditableConfigNames() {
return [
'form_test.object',
];
}
public function buildForm(array $form, FormStateInterface $form_state, $arg = NULL) {
$form['element'] = [
'#markup' => 'The FormTestArgumentsObject::buildForm() method was used for this form.',
];
$form['bananas'] = [
'#type' => 'textfield',
'#default_value' => $arg,
'#title' => $this
->t('Bananas'),
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus($this
->t('The FormTestArgumentsObject::validateForm() method was used for this form.'));
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus($this
->t('The FormTestArgumentsObject::submitForm() method was used for this form.'));
$this
->config('form_test.object')
->set('bananas', $form_state
->getValue('bananas'))
->save();
}
}
Classes