diff --git a/core/lib/Drupal/Core/Controller/DialogController.php b/core/lib/Drupal/Core/Controller/DialogController.php index c8478f8..3340328 100644 --- a/core/lib/Drupal/Core/Controller/DialogController.php +++ b/core/lib/Drupal/Core/Controller/DialogController.php @@ -11,6 +11,7 @@ use Drupal\Core\Ajax\OpenDialogCommand; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -63,11 +64,25 @@ public function dialog(Request $request, $_content, $modal = FALSE) { $callable = $this->controllerResolver->createController($_content); $arguments = $this->controllerResolver->getArguments($request, $callable); $controller_response = call_user_func_array($callable, $arguments); - if ($controller_response->isOk()) { - $content = $controller_response->getContent(); - // @todo Remove use of drupal_get_title() when - // http://drupal.org/node/1871596 is in. - $title = drupal_get_title(); + + if ($controller_response instanceof Response) { + return $controller_response; + } + else { + if (!is_array($controller_response)) { + $content = array( + '#markup' => $controller_response, + ); + } + else { + $content = $controller_response; + } + + // If no title was returned fall back to one defined in the route. + if (!isset($content['#title']) && $request->attributes->has('_title')) { + $content['#title'] = $request->attributes->get('_title'); + } + $response = new AjaxResponse(); // Fetch any modal options passed in from data-dialog-options. if (!($options = $request->request->get('dialogOptions'))) { @@ -96,7 +111,7 @@ public function dialog(Request $request, $_content, $modal = FALSE) { $target = '#' . drupal_html_id("drupal-dialog-$route_name"); } } - $response->addCommand(new OpenDialogCommand($target, $title, $content, $options)); + $response->addCommand(new OpenDialogCommand($target, isset($content['#title']) ? $content['#title'] : '', drupal_render($content), $options)); return $response; } // An error occurred in the subrequest, return that. diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.module b/core/modules/system/tests/modules/ajax_test/ajax_test.module index e358018..3217c41 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.module +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.module @@ -269,8 +269,14 @@ function _ajax_test_dialog($is_modal = FALSE) { /** * Returns example content for dialog tests. + * + * @param string $title + * (optional) The title of the dialog result. + * + * @return array + * A render array as expected by drupal_render(). */ -function ajax_test_dialog_contents() { +function ajax_test_dialog_contents($title = '') { // This is a regular render array; the keys do not have special meaning. $content = array( 'content' => array( @@ -288,6 +294,10 @@ function ajax_test_dialog_contents() { ), ); + if ($title) { + $content['#title'] = $title; + } + return $content; } diff --git a/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php index 53044c5..91d44a1 100644 --- a/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php @@ -17,8 +17,7 @@ class AjaxTestController { */ public function dialogContents() { // Re-use the utility method that returns the example content. - drupal_set_title(t('AJAX Dialog contents')); - return ajax_test_dialog_contents(); + return ajax_test_dialog_contents(t('AJAX Dialog contents')); } }