3 namespace Drupal\form_test;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides a test form object.
13 class FormTestObject extends ConfigFormBase {
18 public function getFormId() {
19 return 'form_test_form_test_object';
25 protected function getEditableConfigNames() {
26 return ['form_test.object'];
32 public function buildForm(array $form, FormStateInterface $form_state) {
33 $form['element'] = ['#markup' => 'The FormTestObject::buildForm() method was used for this form.'];
36 '#type' => 'textfield',
37 '#title' => $this->t('Bananas'),
39 $form['strawberry'] = [
42 '#attributes' => ['id' => 'redstrawberryhiddenfield'],
45 $form['actions']['#type'] = 'actions';
46 $form['actions']['submit'] = [
48 '#value' => $this->t('Save'),
51 $form['#title'] = 'Test dynamic title';
59 public function validateForm(array &$form, FormStateInterface $form_state) {
60 $this->messenger()->addStatus($this->t('The FormTestObject::validateForm() method was used for this form.'));
66 public function submitForm(array &$form, FormStateInterface $form_state) {
67 $this->messenger()->addStatus($this->t('The FormTestObject::submitForm() method was used for this form.'));
68 $this->config('form_test.object')
69 ->set('bananas', $form_state->getValue('bananas'))