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