diff --git a/core/lib/Drupal/Core/AjaxController.php b/core/lib/Drupal/Core/AjaxController.php index c423489..7da1b03 100644 --- a/core/lib/Drupal/Core/AjaxController.php +++ b/core/lib/Drupal/Core/AjaxController.php @@ -57,14 +57,6 @@ public function content(Request $request, $_content) { if ($response instanceof AjaxResponse) { return $response; } - elseif (is_array($response)) { - // Add all commands to the ajax response. - $ajax_response = new AjaxResponse(); - foreach ($response['#commands'] as $command) { - $ajax_response->addCommand($command); - } - $response = $ajax_response; - } else { // Pull the content out of the response. $content = $response->getContent(); diff --git a/core/lib/Drupal/Core/Form/FormAjaxController.php b/core/lib/Drupal/Core/Form/FormAjaxController.php index c2c23fd..2c96fdf 100644 --- a/core/lib/Drupal/Core/Form/FormAjaxController.php +++ b/core/lib/Drupal/Core/Form/FormAjaxController.php @@ -43,7 +43,28 @@ public function content() { $callback = $form_state['triggering_element']['#ajax']['callback']; } if (!empty($callback) && is_callable($callback)) { - return call_user_func_array($callback, array(&$form, &$form_state)); + $result = call_user_func_array($callback, array(&$form, &$form_state)); + + // Ajax callbacks currently returns either the actual ajax response. + if ($result instanceof AjaxResponse) { + return $result; + } + // Or they return array('#type' => 'ajax, '#commands'); + // @todo We could certainly remove this check once we just use an Ajax + // Response all over the place. + elseif (is_array($result) && isset($result['#type']) && $result['#type'] == 'ajax') { + // Add all commands to the ajax response. + $ajax_response = new AjaxResponse(); + foreach ($result['#commands'] as $command) { + $ajax_response->addCommand($command); + } + return $ajax_response; + } + // Or they return just the normal drupal render array, which will then + // be rendered by AjaxController. + else { + return $result; + } } }