You are here

public function WideModalRenderer::renderResponse in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php \Drupal\dialog_renderer_test\Render\MainContent\WideModalRenderer::renderResponse()
  2. 9 core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php \Drupal\dialog_renderer_test\Render\MainContent\WideModalRenderer::renderResponse()

Renders the main content render array into a response.

Parameters

array $main_content: The render array representing the main content.

\Symfony\Component\HttpFoundation\Request $request: The request object, for context.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match, for context.

Return value

\Symfony\Component\HttpFoundation\Response The Response in the format that this implementation supports.

Overrides ModalRenderer::renderResponse

File

core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php, line 47

Class

WideModalRenderer
Default main content renderer for wide modal dialog requests.

Namespace

Drupal\dialog_renderer_test\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 = $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
    ->all('dialogOptions');

  // Override width option.
  switch ($this->mode) {
    case 'wide':
      $options['width'] = 700;
      break;
    case 'extra_wide':
      $options['width'] = 1000;
      break;
  }
  $response
    ->addCommand(new OpenModalDialogCommand($title, $content, $options));
  return $response;
}