Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / modules / js_ajax_test / src / Form / JsAjaxTestForm.php
1 <?php
2
3 namespace Drupal\js_ajax_test\Form;
4
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Form\FormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\js_ajax_test\Ajax\JsAjaxTestCommand;
9
10 /**
11  * Test form for js_ajax_test
12  *
13  * @internal
14  */
15 class JsAjaxTestForm extends FormBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getFormId() {
21     return 'js_ajax_test_form';
22   }
23
24   /**
25    * Form for testing the addition of various types of elements via Ajax.
26    */
27   public function buildForm(array $form, FormStateInterface $form_state) {
28     $form['#attached']['library'][] = 'js_ajax_test/ajax';
29     $form['custom']['#prefix'] = '<div id="js_ajax_test_form_wrapper">';
30     $form['custom']['#suffix'] = '</div>';
31
32     // Button to test for the waitForButton() assertion.
33     $form['test_button'] = [
34       '#type' => 'submit',
35       '#value' => $this->t('Add button'),
36       '#button_type' => 'primary',
37       '#ajax' => [
38         'callback' => [static::class, 'addButton'],
39         'progress' => [
40           'type' => 'throbber',
41           'message' => NULL,
42         ],
43         'wrapper' => 'js_ajax_test_form_wrapper',
44       ],
45     ];
46     return $form;
47   }
48
49   /**
50    * Ajax callback for the "Add button" button.
51    */
52   public static function addButton(array $form, FormStateInterface $form_state) {
53     return (new AjaxResponse())
54       ->addCommand(new JsAjaxTestCommand());
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function submitForm(array &$form, FormStateInterface $form_state) {
61     // An empty implementation, as we never submit the actual form.
62   }
63
64 }