852cf4435214dd02434f1e7434b5c169fcce832f
[yaffs-website] / web / core / modules / system / tests / modules / ajax_forms_test / src / Form / AjaxFormsTestLazyLoadForm.php
1 <?php
2
3 namespace Drupal\ajax_forms_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form builder: Builds a form that triggers a simple AJAX callback.
10  */
11 class AjaxFormsTestLazyLoadForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'ajax_forms_test_lazy_load_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24     // We attach a JavaScript setting, so that one of the generated AJAX
25     // commands will be a settings command. We can then check the settings
26     // command to ensure that the 'currentPath' setting is not part
27     // of the Ajax response.
28     $form['#attached']['drupalSettings']['test'] = 'currentPathUpdate';
29     $form['add_files'] = [
30       '#title' => $this->t('Add files'),
31       '#type' => 'checkbox',
32       '#default_value' => FALSE,
33     ];
34     $form['submit'] = [
35       '#type' => 'submit',
36       '#value' => $this->t('Submit'),
37       '#ajax' => [
38         'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper',
39         'callback' => 'ajax_forms_test_lazy_load_form_ajax',
40       ],
41       '#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>',
42     ];
43
44     return $form;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function submitForm(array &$form, FormStateInterface $form_state) {
51     $form_state->setRebuild();
52   }
53
54 }