Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestRedirectForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Form builder to detect form redirect.
11  */
12 class FormTestRedirectForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'form_test_redirect';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $form['redirection'] = [
26       '#type' => 'checkbox',
27       '#title' => t('Use redirection'),
28     ];
29     $form['destination'] = [
30       '#type' => 'textfield',
31       '#title' => t('Redirect destination'),
32       '#states' => [
33         'visible' => [
34           ':input[name="redirection"]' => ['checked' => TRUE],
35         ],
36       ],
37     ];
38     $form['submit'] = [
39       '#type' => 'submit',
40       '#value' => t('Submit'),
41     ];
42
43     return $form;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function submitForm(array &$form, FormStateInterface $form_state) {
50     if (!$form_state->isValueEmpty('redirection')) {
51       if (!$form_state->isValueEmpty('destination')) {
52         // The destination is a random URL, so we can't use routed URLs.
53         // @todo Revist this in https://www.drupal.org/node/2418219.
54         $form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
55       }
56     }
57     else {
58       $form_state->disableRedirect();
59     }
60   }
61
62 }