3 namespace Drupal\ajax_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Dummy form for testing DialogRenderer with _form routes.
11 class AjaxTestForm extends FormBase {
16 public function getFormId() {
17 return 'ajax_test_form';
23 public function buildForm(array $form, FormStateInterface $form_state) {
25 $form['#action'] = \Drupal::url('ajax_test.dialog');
27 $form['description'] = [
28 '#markup' => '<p>' . $this->t("Ajax Form contents description.") . '</p>',
34 $form['actions']['submit'] = [
36 '#value' => $this->t('Do it'),
38 $form['actions']['preview'] = [
40 '#value' => $this->t('Preview'),
41 // No regular submit-handler. This form only works via JavaScript.
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',
62 public function submitForm(array &$form, FormStateInterface $form_state) {}
67 public function validateForm(array &$form, FormStateInterface $form_state) {}