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 FormTestServiceObject extends ConfigFormBase {
18 public function getFormId() {
19 return 'form_test_form_test_service_object';
25 protected function getEditableConfigNames() {
26 return ['form_test.object'];
32 public function buildForm(array $form, FormStateInterface $form_state) {
33 $form['element'] = ['#markup' => 'The FormTestServiceObject::buildForm() method was used for this form.'];
36 '#type' => 'textfield',
37 '#default_value' => 'brown',
38 '#title' => $this->t('Bananas'),
41 $form['actions']['#type'] = 'actions';
42 $form['actions']['submit'] = [
44 '#value' => $this->t('Save'),
52 public function validateForm(array &$form, FormStateInterface $form_state) {
53 $this->messenger()->addStatus($this->t('The FormTestServiceObject::validateForm() method was used for this form.'));
59 public function submitForm(array &$form, FormStateInterface $form_state) {
60 $this->messenger()->addStatus($this->t('The FormTestServiceObject::submitForm() method was used for this form.'));
61 $this->config('form_test.object', FALSE)
62 ->set('bananas', $form_state->getValue('bananas'))