You are here

public function Callbacks::datetimeCallback in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php \Drupal\ajax_forms_test\Callbacks::datetimeCallback()

Ajax callback triggered by datetime.

File

core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php, line 39

Class

Callbacks
Simple object for testing methods as Ajax callbacks.

Namespace

Drupal\ajax_forms_test

Code

public function datetimeCallback($form, FormStateInterface $form_state) {
  $datetime = $form_state
    ->getValue('datetime')['date'] . ' ' . $form_state
    ->getValue('datetime')['time'];
  $response = new AjaxResponse();
  $response
    ->addCommand(new HtmlCommand('#ajax_datetime_value', sprintf('<div>%s</div>', $datetime)));
  $response
    ->addCommand(new DataCommand('#ajax_datetime_value', 'form_state_value_datetime', $datetime));
  return $response;
}