Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Render / MainContent / ModalRenderer.php
1 <?php
2
3 namespace Drupal\Core\Render\MainContent;
4
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\OpenModalDialogCommand;
7 use Drupal\Core\Routing\RouteMatchInterface;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * Default main content renderer for modal dialog requests.
12  */
13 class ModalRenderer extends DialogRenderer {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
19     $response = new AjaxResponse();
20
21     // First render the main content, because it might provide a title.
22     $content = drupal_render_root($main_content);
23
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']);
28
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());
31
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', []);
35
36     $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
37     return $response;
38   }
39
40 }