08fd6f69a0ffdea9c87974d3e6ffd7d285d9e415
[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 class TestForm extends FormBase {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getFormId() {
14     return 'block_test_form_test';
15   }
16
17   /**
18    * {@inheritdoc}
19    */
20   public function buildForm(array $form, FormStateInterface $form_state) {
21     $form['email'] = [
22       '#type' => 'email',
23       '#title' => $this->t('Your .com email address.')
24     ];
25
26     $form['show'] = [
27       '#type' => 'submit',
28       '#value' => $this->t('Submit'),
29     ];
30
31     return $form;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function validateForm(array &$form, FormStateInterface $form_state) {
38     if (strpos($form_state->getValue('email'), '.com') === FALSE) {
39       $form_state->setErrorByName('email', $this->t('This is not a .com email address.'));
40     }
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function submitForm(array &$form, FormStateInterface $form_state) {
47     drupal_set_message($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
48   }
49
50 }