X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fform_test%2Fsrc%2FForm%2FFormTestRedirectForm.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fform_test%2Fsrc%2FForm%2FFormTestRedirectForm.php;h=4768acf901f5f549afddff75425ce779056a8438;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php b/web/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php new file mode 100644 index 000000000..4768acf90 --- /dev/null +++ b/web/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php @@ -0,0 +1,62 @@ + 'checkbox', + '#title' => t('Use redirection'), + ]; + $form['destination'] = [ + '#type' => 'textfield', + '#title' => t('Redirect destination'), + '#states' => [ + 'visible' => [ + ':input[name="redirection"]' => ['checked' => TRUE], + ], + ], + ]; + $form['submit'] = [ + '#type' => 'submit', + '#value' => t('Submit'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + if (!$form_state->isValueEmpty('redirection')) { + if (!$form_state->isValueEmpty('destination')) { + // The destination is a random URL, so we can't use routed URLs. + // @todo Revist this in https://www.drupal.org/node/2418219. + $form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination'))); + } + } + else { + $form_state->disableRedirect(); + } + } + +}