Updated to Drupal 8.5. Core Media not yet in use.
[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  * @internal
13  */
14 class FormTestUrlForm extends FormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'form_test_url';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function buildForm(array $form, FormStateInterface $form_state) {
27     $form['url'] = [
28       '#type' => 'url',
29       '#title' => 'Optional URL',
30       '#description' => 'An optional URL field.',
31     ];
32     $form['url_required'] = [
33       '#type' => 'url',
34       '#title' => 'Required URL',
35       '#description' => 'A required URL field.',
36       '#required' => TRUE,
37     ];
38     $form['submit'] = [
39       '#type' => 'submit',
40       '#value' => 'Submit',
41     ];
42     return $form;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function submitForm(array &$form, FormStateInterface $form_state) {
49     $form_state->setResponse(new JsonResponse($form_state->getValues()));
50   }
51
52 }