You are here

class ModalRenderer in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php \Drupal\Core\Render\MainContent\ModalRenderer

Default main content renderer for modal dialog requests.

Hierarchy

Expanded class hierarchy of ModalRenderer

1 string reference to 'ModalRenderer'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ModalRenderer
main_content_renderer.modal in core/core.services.yml
Drupal\Core\Render\MainContent\ModalRenderer

File

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

Namespace

Drupal\Core\Render\MainContent
View source
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 = drupal_render_root($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', array());
    $response
      ->addCommand(new OpenModalDialogCommand($title, $content, $options));
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DialogRenderer::$titleResolver protected property The title resolver.
DialogRenderer::determineTargetSelector protected function Determine the target selector for the OpenDialogCommand.
DialogRenderer::__construct public function Constructs a new DialogRenderer.
ModalRenderer::renderResponse public function Renders the main content render array into a response. Overrides DialogRenderer::renderResponse