f4a89bf9fd4eb8dbe22ea83ed12089744f8da617
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / FormTestServiceObject.php
1 <?php
2
3 namespace Drupal\form_test;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a test form object.
10  *
11  * @internal
12  */
13 class FormTestServiceObject extends ConfigFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'form_test_form_test_service_object';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function getEditableConfigNames() {
26     return ['form_test.object'];
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function buildForm(array $form, FormStateInterface $form_state) {
33     $form['element'] = ['#markup' => 'The FormTestServiceObject::buildForm() method was used for this form.'];
34
35     $form['bananas'] = [
36       '#type' => 'textfield',
37       '#default_value' => 'brown',
38       '#title' => $this->t('Bananas'),
39     ];
40
41     $form['actions']['#type'] = 'actions';
42     $form['actions']['submit'] = [
43       '#type' => 'submit',
44       '#value' => $this->t('Save'),
45     ];
46     return $form;
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function validateForm(array &$form, FormStateInterface $form_state) {
53     $this->messenger()->addStatus($this->t('The FormTestServiceObject::validateForm() method was used for this form.'));
54   }
55
56   /**
57    * {@inheritdoc}
58    */
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'))
63       ->save();
64   }
65
66 }