55b13f78258005703a87b08f7688bd88b39baff4
[yaffs-website] / web / core / modules / block / tests / modules / block_test / src / Form / TestForm.php
1 <?php
2
3 namespace Drupal\block_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form that performs base block form test.
10  *
11  * @internal
12  */
13 class TestForm extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'block_test_form_test';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function buildForm(array $form, FormStateInterface $form_state) {
26     $form['email'] = [
27       '#type' => 'email',
28       '#title' => $this->t('Your .com email address.'),
29     ];
30
31     $form['show'] = [
32       '#type' => 'submit',
33       '#value' => $this->t('Submit'),
34     ];
35
36     return $form;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function validateForm(array &$form, FormStateInterface $form_state) {
43     if (strpos($form_state->getValue('email'), '.com') === FALSE) {
44       $form_state->setErrorByName('email', $this->t('This is not a .com email address.'));
45     }
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function submitForm(array &$form, FormStateInterface $form_state) {
52     $this->messenger()->addStatus($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
53   }
54
55 }