0ad80c9250a1df953389553678a722f641eba077
[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 checkbox.
27    */
28   public function checkboxCallback($form, FormStateInterface $form_state) {
29     $response = new AjaxResponse();
30     $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
31     $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
32     return $response;
33   }
34
35   /**
36    * Ajax callback triggered by the checkbox in a #group.
37    */
38   public function checkboxGroupCallback($form, FormStateInterface $form_state) {
39     return $form['checkbox_in_group_wrapper'];
40   }
41
42 }