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