Displays content in a dialog.
\Symfony\Component\HttpFoundation\RequestRequest $request: The request object.
callable $_content: The body content callable that contains the body region of this page.
bool $modal: (optional) TRUE to render a modal dialog. Defaults to FALSE.
\Drupal\Core\Ajax\AjaxResponse AjaxResponse to return the content wrapper in a dialog.
public function dialog(Request $request, $_content, $modal = FALSE) {
$subrequest = $this
->forward($request, $_content);
if ($subrequest
->isOk()) {
$content = $subrequest
->getContent();
// @todo Remove use of drupal_get_title() when
// http://drupal.org/node/1871596 is in.
$title = drupal_get_title();
$response = new AjaxResponse();
// Fetch any modal options passed in from data-dialog-options.
if (!($options = $request->request
->get('dialogOptions'))) {
$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;
}
// This shouldn't be passed on to jQuery.ui.dialog.
unset($options['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($target, $title, $content, $options));
return $response;
}
// An error occurred in the subrequest, return that.
return $subrequest;
}