annotate core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php @ 19:fa3358dc1485 tip

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