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 / Form / FormTestStatePersistForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form constructor for testing form state persistence.
10  *
11  * @internal
12  */
13 class FormTestStatePersistForm extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'form_test_state_persist';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function buildForm(array $form, FormStateInterface $form_state) {
26     $form['title'] = [
27       '#type' => 'textfield',
28       '#title' => 'title',
29       '#default_value' => 'DEFAULT',
30       '#required' => TRUE,
31     ];
32     $form_state->set('value', 'State persisted.');
33
34     $form['submit'] = [
35       '#type' => 'submit',
36       '#value' => t('Submit'),
37     ];
38     return $form;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function submitForm(array &$form, FormStateInterface $form_state) {
45     $this->messenger()->addStatus($form_state->get('value'));
46     $form_state->setRebuild();
47   }
48
49 }