ModalRenderer.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php
  2. 8.9.x core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php
  3. 10 core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php

Namespace

Drupal\Core\Render\MainContent

File

core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php

View source
<?php

namespace Drupal\Core\Render\MainContent;

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Default main content renderer for modal dialog requests.
 */
class ModalRenderer extends DialogRenderer {
    
    /**
     * {@inheritdoc}
     */
    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']);
        // Determine the title.
        $title = $this->getTitleAsStringable($main_content, $request, $route_match);
        // Determine the dialog options for the OpenDialogCommand.
        $options = $this->getDialogOptions($request);
        $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
        return $response;
    }

}

Classes

Title Deprecated Summary
ModalRenderer Default main content renderer for modal dialog requests.

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