You are here

class BareHtmlPageRenderer in Drupal 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php \Drupal\Core\Render\BareHtmlPageRenderer
  2. 8 core/lib/Drupal/Core/ProxyClass/Render/BareHtmlPageRenderer.php \Drupal\Core\ProxyClass\Render\BareHtmlPageRenderer
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php \Drupal\Core\Render\BareHtmlPageRenderer

Default bare HTML page renderer.

Hierarchy

Expanded class hierarchy of BareHtmlPageRenderer

1 string reference to 'BareHtmlPageRenderer'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses BareHtmlPageRenderer
bare_html_page_renderer in core/core.services.yml
Drupal\Core\Render\BareHtmlPageRenderer

File

core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php, line 8

Namespace

Drupal\Core\Render
View source
class BareHtmlPageRenderer implements BareHtmlPageRendererInterface {

  /**
   * The renderer service.
   *
   * @var \Drupal\Core\Render\Renderer
   */
  protected $renderer;

  /**
   * The HTML response attachments processor service.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
   */
  protected $htmlResponseAttachmentsProcessor;

  /**
   * Constructs a new BareHtmlPageRenderer.
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
   * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
   *   The HTML response attachments processor service.
   */
  public function __construct(RendererInterface $renderer, AttachmentsResponseProcessorInterface $html_response_attachments_processor) {
    $this->renderer = $renderer;
    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
  }

  /**
   * {@inheritdoc}
   */
  public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []) {
    $attributes = [
      'class' => [
        str_replace('_', '-', $page_theme_property),
      ],
    ];
    $html = [
      '#type' => 'html',
      '#attributes' => $attributes,
      'page' => [
        '#type' => 'page',
        '#theme' => $page_theme_property,
        '#title' => $title,
        'content' => $content,
      ] + $page_additions,
    ];

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

    // Add the bare minimum of attachments from the system module and the
    // current maintenance theme.
    system_page_attachments($html['page']);
    $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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BareHtmlPageRenderer::$htmlResponseAttachmentsProcessor protected property The HTML response attachments processor service.
BareHtmlPageRenderer::$renderer protected property The renderer service.
BareHtmlPageRenderer::renderBarePage public function Renders a bare page. Overrides BareHtmlPageRendererInterface::renderBarePage
BareHtmlPageRenderer::__construct public function Constructs a new BareHtmlPageRenderer.