8b01c32b561daa2895ff316b364896d5c628eafa
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestEmailForm.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 'email' elements.
11  *
12  * @internal
13  */
14 class FormTestEmailForm extends FormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'form_test_email';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function buildForm(array $form, FormStateInterface $form_state) {
27     $form['email'] = [
28       '#type' => 'email',
29       '#title' => 'Email address',
30       '#description' => 'An email address.',
31     ];
32     $form['email_required'] = [
33       '#type' => 'email',
34       '#title' => 'Address',
35       '#required' => TRUE,
36       '#description' => 'A required email address field.',
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 }