comparison core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core\Render;
4
5 /**
6 * Default bare HTML page renderer.
7 */
8 class BareHtmlPageRenderer implements BareHtmlPageRendererInterface {
9
10 /**
11 * The renderer service.
12 *
13 * @var \Drupal\Core\Render\Renderer
14 */
15 protected $renderer;
16
17 /**
18 * The HTML response attachments processor service.
19 *
20 * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
21 */
22 protected $htmlResponseAttachmentsProcessor;
23
24 /**
25 * Constructs a new BareHtmlPageRenderer.
26 *
27 * @param \Drupal\Core\Render\RendererInterface $renderer
28 * The renderer service.
29 * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
30 * 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 * {@inheritdoc}
39 */
40 public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []) {
41 $attributes = [
42 'class' => [
43 str_replace('_', '-', $page_theme_property),
44 ],
45 ];
46 $html = [
47 '#type' => 'html',
48 '#attributes' => $attributes,
49 'page' => [
50 '#type' => 'page',
51 '#theme' => $page_theme_property,
52 '#title' => $title,
53 'content' => $content,
54 ] + $page_additions,
55 ];
56
57 // For backwards compatibility.
58 // @todo In Drupal 9, add a $show_messages function parameter.
59 if (!isset($page_additions['#show_messages']) || $page_additions['#show_messages'] === TRUE) {
60 $html['page']['highlighted'] = ['#type' => 'status_messages'];
61 }
62
63 // Add the bare minimum of attachments from the system module and the
64 // current maintenance theme.
65 system_page_attachments($html['page']);
66 $this->renderer->renderRoot($html);
67
68 $response = new HtmlResponse();
69 $response->setContent($html);
70 // Process attachments, because this does not go via the regular render
71 // pipeline, but will be sent directly.
72 $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response);
73 return $response;
74 }
75
76 }