diff -u b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php --- b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php +++ b/core/modules/file/lib/Drupal/file/Controller/FileWidgetAjaxController.php @@ -21,10 +21,10 @@ class FileWidgetAjaxController extends FormAjaxController { /** - * Processes AJAX file uploads. + * Processes AJAX file uploads and deletions. * * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. + * The current request object. * * @return \Drupal\Core\Ajax\AjaxResponse * An AjaxResponse object. diff -u b/core/modules/system/lib/Drupal/system/Controller/FormAjaxController.php b/core/modules/system/lib/Drupal/system/Controller/FormAjaxController.php --- b/core/modules/system/lib/Drupal/system/Controller/FormAjaxController.php +++ b/core/modules/system/lib/Drupal/system/Controller/FormAjaxController.php @@ -12,18 +12,23 @@ use Symfony\Component\HttpKernel\Exception\HttpException; /** - * Defines a controller to respond to form AJAX requests. + * Defines a controller to respond to form Ajax requests. */ class FormAjaxController { /** - * Handle form AJAX request. + * Processes an Ajax form submission. * * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. + * The current request object. * - * @return \Symfony\Component\HttpFoundation\Response - * A Symfony response object. + * @return mixed + * Whatever is returned by the triggering element's #ajax['callback'] + * function. One of: + * - A render array containing the new or updated content to return to the + * browser. This is commonly an element within the rebuilt form. + * - A \Drupal\Core\Ajax\AjaxResponse object containing commands for the + * browser to process. * * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface */ @@ -53,7 +58,7 @@ * pulls the form info from the request body. * * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. + * The current request object. * * @return array * An array containing the $form and $form_state. Use the list() function diff -u b/core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php @@ -53,17 +53,13 @@ } - // Verify that an AJAX element without a callback throws error code 500. - $edit = array( - 'select_empty_callback' => 'red', - ); - $commands = $this->drupalPostAJAX('ajax_forms_test_get_form', $edit, 'select_empty_callback'); - $this->assertResponse(500); - - // Verify that an AJAX element with a nonexistent callback throws error code 500. - $edit = array( - 'select_nonexistent_callback' => 'red', - ); - $commands = $this->drupalPostAJAX('ajax_forms_test_get_form', $edit, 'select_nonexistent_callback'); - $this->assertResponse(500); + // Verify that AJAX elements with invalid callbacks return error code 500. + foreach (array('null', 'empty', 'nonexistent') as $key) { + $element_name = 'select_' . $key . '_callback'; + $edit = array( + $element_name => 'red', + ); + $commands = $this->drupalPostAJAX('ajax_forms_test_get_form', $edit, $element_name); + $this->assertResponse(500); + } } } diff -u b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module --- b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module +++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module @@ -73,17 +73,20 @@ '#value' => t('submit'), ); - $form['select_empty_callback'] = array( - '#type' => 'select', - '#options' => array('red' => 'red'), - '#ajax' => array('callback' => ''), - ); - - $form['select_nonexistent_callback'] = array( - '#type' => 'select', - '#options' => array('red' => 'red'), - '#ajax' => array('callback' => 'some_function_that_does_not_exist'), + // This is for testing invalid callbacks that should return a 500 error in + // \Drupal\system\FormAjaxController::content(). + $invalid_callbacks = array( + 'null' => NULL, + 'empty' => '', + 'nonexistent' => 'some_function_that_does_not_exist', ); + foreach ($invalid_callbacks as $key => $value) { + $form['select_' . $key . '_callback'] = array( + '#type' => 'select', + '#options' => array('red' => 'red'), + '#ajax' => array('callback' => $value), + ); + } return $form; }