3 namespace Drupal\Core\Render\MainContent;
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\OpenModalDialogCommand;
7 use Drupal\Core\Routing\RouteMatchInterface;
8 use Symfony\Component\HttpFoundation\Request;
11 * Default main content renderer for modal dialog requests.
13 class ModalRenderer extends DialogRenderer {
18 public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
19 $response = new AjaxResponse();
21 // First render the main content, because it might provide a title.
22 $content = drupal_render_root($main_content);
24 // Attach the library necessary for using the OpenModalDialogCommand and set
25 // the attachments for this Ajax response.
26 $main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
27 $response->setAttachments($main_content['#attached']);
29 // If the main content doesn't provide a title, use the title resolver.
30 $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
32 // Determine the title: use the title provided by the main content if any,
33 // otherwise get it from the routing information.
34 $options = $request->request->get('dialogOptions', []);
36 $response->addCommand(new OpenModalDialogCommand($title, $content, $options));