Version 1
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestUrlForm.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 Symfony\Component\HttpFoundation\JsonResponse;
8
9 /**
10  * Form constructor for testing #type 'url' elements.
11  */
12 class FormTestUrlForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'form_test_url';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $form['url'] = [
26       '#type' => 'url',
27       '#title' => 'Optional URL',
28       '#description' => 'An optional URL field.',
29     ];
30     $form['url_required'] = [
31       '#type' => 'url',
32       '#title' => 'Required URL',
33       '#description' => 'A required URL field.',
34       '#required' => TRUE,
35     ];
36     $form['submit'] = [
37       '#type' => 'submit',
38       '#value' => 'Submit',
39     ];
40     return $form;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function submitForm(array &$form, FormStateInterface $form_state) {
47     $form_state->setResponse(new JsonResponse($form_state->getValues()));
48   }
49
50 }