ea431efa5adc1cac029018a6f40fcfca62a2cbcd
[yaffs-website] / web / core / modules / system / tests / modules / ajax_test / src / Form / AjaxTestForm.php
1 <?php
2
3 namespace Drupal\ajax_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Dummy form for testing DialogRenderer with _form routes.
10  */
11 class AjaxTestForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'ajax_test_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24
25     $form['#action'] = \Drupal::url('ajax_test.dialog');
26
27     $form['description'] = [
28       '#markup' => '<p>' . $this->t("Ajax Form contents description.") . '</p>',
29     ];
30
31     $form['actions'] = [
32       '#type' => 'actions',
33     ];
34     $form['actions']['submit'] = [
35       '#type' => 'submit',
36       '#value' => $this->t('Do it'),
37     ];
38     $form['actions']['preview'] = [
39       '#type' => 'submit',
40       '#value' => $this->t('Preview'),
41       // No regular submit-handler. This form only works via JavaScript.
42       '#submit' => [],
43       '#ajax' => [
44         // This means the ::preview() method on this class would be invoked in
45         // case of a click event. However, since Drupal core's test runner only
46         // is able to execute PHP, not JS, there is no point in actually
47         // implementing this method, because we can never let it be called from
48         // JS; we'd have to manually call it from PHP, at which point we would
49         // not actually be testing it.
50         // Therefore we consciously choose to not implement this method, because
51         // we cannot meaningfully test it anyway.
52         'callback' => '::preview',
53         'event' => 'click',
54       ],
55     ];
56     return $form;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function submitForm(array &$form, FormStateInterface $form_state) {}
63
64   /**
65    * {@inheritdoc}
66    */
67   public function validateForm(array &$form, FormStateInterface $form_state) {}
68
69 }