function ModalRenderer::renderResponse

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php \Drupal\Core\Render\MainContent\ModalRenderer::renderResponse()
  2. 10 core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php \Drupal\Core\Render\MainContent\ModalRenderer::renderResponse()
  3. 11.x core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php \Drupal\Core\Render\MainContent\ModalRenderer::renderResponse()

Overrides DialogRenderer::renderResponse

1 method overrides ModalRenderer::renderResponse()
WideModalRenderer::renderResponse in core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php
Renders the main content render array into a response.

File

core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php, line 18

Class

ModalRenderer
Default main content renderer for modal dialog requests.

Namespace

Drupal\Core\Render\MainContent

Code

public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
    $response = new AjaxResponse();
    // First render the main content, because it might provide a title.
    $content = $this->renderer
        ->renderRoot($main_content);
    // Attach the library necessary for using the OpenModalDialogCommand and set
    // the attachments for this Ajax response.
    $main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response->setAttachments($main_content['#attached']);
    // If the main content doesn't provide a title, use the title resolver.
    $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver
        ->getTitle($request, $route_match->getRouteObject());
    // Determine the title: use the title provided by the main content if any,
    // otherwise get it from the routing information.
    $options = $request->request
        ->get('dialogOptions', []);
    $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
    return $response;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.