BareHtmlPageRenderer.php 2.25 KB
Newer Older
1 2 3 4 5
<?php

namespace Drupal\Core\Render;

/**
6
 * Default bare HTML page renderer.
7 8 9
 */
class BareHtmlPageRenderer implements BareHtmlPageRendererInterface {

10 11 12 13 14 15 16
  /**
   * The renderer service.
   *
   * @var \Drupal\Core\Render\Renderer
   */
  protected $renderer;

17 18 19 20 21 22 23
  /**
   * The HTML response attachments processor service.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
   */
  protected $htmlResponseAttachmentsProcessor;

24 25 26 27 28
  /**
   * Constructs a new BareHtmlPageRenderer.
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
29 30
   * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
   *   The HTML response attachments processor service.
31
   */
32
  public function __construct(RendererInterface $renderer, AttachmentsResponseProcessorInterface $html_response_attachments_processor) {
33
    $this->renderer = $renderer;
34
    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
35 36
  }

37 38 39
  /**
   * {@inheritdoc}
   */
40
  public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []) {
41 42
    $attributes = [
      'class' => [
43
        str_replace('_', '-', $page_theme_property),
44 45 46 47 48 49 50 51 52 53 54 55 56
      ],
    ];
    $html = [
      '#type' => 'html',
      '#attributes' => $attributes,
      'page' => [
        '#type' => 'page',
        '#theme' => $page_theme_property,
        '#title' => $title,
        'content' => $content,
      ] + $page_additions,
    ];

57 58 59
    // For backwards compatibility.
    // @todo In Drupal 9, add a $show_messages function parameter.
    if (!isset($page_additions['#show_messages']) || $page_additions['#show_messages'] === TRUE) {
60
      $html['page']['highlighted'] = ['#type' => 'status_messages'];
61 62
    }

63 64 65
    // Add the bare minimum of attachments from the system module and the
    // current maintenance theme.
    system_page_attachments($html['page']);
66 67 68 69 70 71 72 73
    $this->renderer->renderRoot($html);

    $response = new HtmlResponse();
    $response->setContent($html);
    // Process attachments, because this does not go via the regular render
    // pipeline, but will be sent directly.
    $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response);
    return $response;
74 75 76
  }

}