Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / FormTestObject.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 FormTestObject extends ConfigFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'form_test_form_test_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 FormTestObject::buildForm() method was used for this form.'];
34
35     $form['bananas'] = [
36       '#type' => 'textfield',
37       '#title' => $this->t('Bananas'),
38     ];
39     $form['strawberry'] = [
40       '#type' => 'hidden',
41       '#value' => 'red',
42       '#attributes' => ['id' => 'redstrawberryhiddenfield'],
43     ];
44
45     $form['actions']['#type'] = 'actions';
46     $form['actions']['submit'] = [
47       '#type' => 'submit',
48       '#value' => $this->t('Save'),
49     ];
50
51     $form['#title'] = 'Test dynamic title';
52
53     return $form;
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function validateForm(array &$form, FormStateInterface $form_state) {
60     $this->messenger()->addStatus($this->t('The FormTestObject::validateForm() method was used for this form.'));
61   }
62
63   /**
64    * {@inheritdoc}
65    */
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'))
70       ->save();
71   }
72
73 }