Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / modules / ajax_forms_test / src / Callbacks.php
1 <?php
2
3 namespace Drupal\ajax_forms_test;
4
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\DataCommand;
7 use Drupal\Core\Ajax\HtmlCommand;
8 use Drupal\Core\Form\FormStateInterface;
9
10 /**
11  * Simple object for testing methods as Ajax callbacks.
12  */
13 class Callbacks {
14
15   /**
16    * Ajax callback triggered by select.
17    */
18   public function selectCallback($form, FormStateInterface $form_state) {
19     $response = new AjaxResponse();
20     $response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state->getValue('select')));
21     $response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state->getValue('select')));
22     return $response;
23   }
24
25   /**
26    * Ajax callback triggered by date.
27    */
28   public function dateCallback($form, FormStateInterface $form_state) {
29     $response = new AjaxResponse();
30     $response->addCommand(new HtmlCommand('#ajax_date_value', $form_state->getValue('date')));
31     $response->addCommand(new DataCommand('#ajax_date_value', 'form_state_value_date', $form_state->getValue('date')));
32     return $response;
33   }
34
35   /**
36    * Ajax callback triggered by datetime.
37    */
38   public function datetimeCallback($form, FormStateInterface $form_state) {
39     $datetime = $form_state->getValue('datetime')['date'] . ' ' . $form_state->getValue('datetime')['time'];
40
41     $response = new AjaxResponse();
42     $response->addCommand(new HtmlCommand('#ajax_datetime_value', $datetime));
43     $response->addCommand(new DataCommand('#ajax_datetime_value', 'form_state_value_datetime', $datetime));
44     return $response;
45   }
46
47   /**
48    * Ajax callback triggered by checkbox.
49    */
50   public function checkboxCallback($form, FormStateInterface $form_state) {
51     $response = new AjaxResponse();
52     $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
53     $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
54     return $response;
55   }
56
57   /**
58    * Ajax callback to confirm image button was submitted.
59    */
60   public function imageButtonCallback($form, FormStateInterface $form_state) {
61     $response = new AjaxResponse();
62     $response->addCommand(new HtmlCommand('#ajax_image_button_result', "<div id='ajax-1-more-div'>Something witty!</div>"));
63     return $response;
64   }
65
66   /**
67    * Ajax callback triggered by the checkbox in a #group.
68    */
69   public function checkboxGroupCallback($form, FormStateInterface $form_state) {
70     return $form['checkbox_in_group_wrapper'];
71   }
72
73 }