commit cddb474cde975a025245676d0ea104b427e07f8e Author: Lee Rowlands Date: Tue Mar 26 20:00:04 2013 +1000 Patch 31 diff --git a/core/lib/Drupal/Core/Ajax/DialogController.php b/core/lib/Drupal/Core/Ajax/DialogController.php index bf41001..5fe3c9a 100644 --- a/core/lib/Drupal/Core/Ajax/DialogController.php +++ b/core/lib/Drupal/Core/Ajax/DialogController.php @@ -21,13 +21,12 @@ class DialogController extends ContainerAware { * * @param Request $request * The request object. - * @param callable $_content + * @param callable $content * The body content callable that contains the body region of this page. * * @return \Symfony\Component\HttpFoundation\Response * A response object. */ - protected function forward($request, $content) { // @todo When we have a Generator, we can replace the forward() call with // a render() call, which would handle ESI and hInclude as well. That will @@ -69,7 +68,7 @@ public function modal(Request $request, $_content) { * The request object. * @param callable $_content * The body content callable that contains the body region of this page. - * @parm bool $modal + * @param bool $modal * (optional) TRUE to render a modal dialog. Defaults to FALSE. * * @return \Drupal\Core\Ajax\AjaxResponse @@ -86,19 +85,46 @@ public function dialog(Request $request, $_content, $modal = FALSE) { $title = $output['title']['#value']; unset($output['title']); } + else { + // Legacy fallback. + // @todo remove when http://drupal.org/node/1830588 lands. + $title = drupal_get_title(); + } $content = drupal_render($output); } else { // Legacy fallback. + // @todo remove when http://drupal.org/node/1830588 lands and all routes + // converted to return render arrays. $title = drupal_get_title(); $content = $output; } $response = new AjaxResponse(); - $options = array('width' => '700'); + // Fetch any modal options passed in from data-dialog-options. + if (!($options = $request->request->get('dialog_options'))) { + $options = array(); + } + // Set modal flag and re-use the modal id. if ($modal) { $options['modal'] = TRUE; + $target = '#drupal-modal'; + } + else { + // Generate the target wrapper for the dialog. + if (isset($options['target'])) { + // If the target was nominated in the incoming options, use that. + $target = $options['target']; + // Ensure the target includes the #. + if (substr($target, 0, 1) != '#') { + $target = '#' . $target; + } + } + else { + // Generate a target based on the controller. + $target = '#drupal-dialog-' . drupal_html_id(drupal_clean_css_identifier(drupal_strtolower($_content))); + } } - $response->addCommand(new OpenDialogCommand('#drupal-modal', $title, $content, $options)); + $response->addCommand(new OpenDialogCommand($target, $title, $content, $options)); return $response; } // An error occurred in the subrequest, return that. diff --git a/core/misc/ajax.js b/core/misc/ajax.js index deb1de5..d74194e 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -55,6 +55,9 @@ Drupal.behaviors.AJAX = { if ($(this).data('accepts')) { element_settings.accepts = $(this).data('accepts'); } + if ($(this).data('dialog-options')) { + element_settings.dialog = $(this).data('dialog-options'); + } var base = $(this).attr('id'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); @@ -208,6 +211,10 @@ Drupal.ajax = function (base, element, element_settings) { type: 'POST' }; + if (element_settings.dialog) { + ajax.options.data['dialog_options'] = element_settings.dialog; + } + // Bind the ajaxSubmit function to the element event. $(ajax.element).bind(element_settings.event, function (event) { return ajax.eventResponse(this, event);