Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created May 16, 2014 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EclipseGc/818113ac9c15439ec020 to your computer and use it in GitHub Desktop.
Save EclipseGc/818113ac9c15439ec020 to your computer and use it in GitHub Desktop.
services:
html_fragment_renderer:
class: Drupal\display\DisplayHtmlFragmentRenderer
arguments: ['@language_manager']
<?php
/**
* @file
* Contains \Drupal\display\DisplayHtmlFragmentRenderer
*/
namespace Drupal\display;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Page\DefaultHtmlFragmentRenderer;
use Drupal\Core\Page\HtmlFragment;
use Drupal\Core\Page\HtmlFragmentRendererInterface;
use Drupal\Core\Page\HtmlPage;
/**
* Default page rendering engine.
*/
class DisplayHtmlFragmentRenderer extends DefaultHtmlFragmentRenderer {
/**
* {@inheritdoc}
*/
public function render(HtmlFragment $fragment, $status_code = 200) {
// Converts the given HTML fragment which represents the main content region
// of the page into a render array.
$page_content['main'] = array(
'#markup' => $fragment->getContent(),
'#cache' => array('tags' => $fragment->getCacheTags()),
);
$page_content['#title'] = $fragment->getTitle();
// Build the full page array by calling drupal_prepare_page(), which invokes
// hook_page_build(). This adds the other regions to the page.
$page_array = drupal_prepare_page($page_content);
// Build the HtmlPage object.
$page = new HtmlPage('', array(), $fragment->getTitle());
$page = $this->preparePage($page, $page_array);
$page->setBodyTop(drupal_render($page_array['page_top']));
$page->setBodyBottom(drupal_render($page_array['page_bottom']));
$page->setContent(drupal_render($page_array));
// Collect cache tags for all the content in all the regions on the page.
$tags = $page_array['#cache']['tags'];
// Enforce the generic "content" cache tag on all pages.
// @todo Remove the "content" cache tag. @see https://drupal.org/node/2124957
$tags['content'] = TRUE;
$page->setCacheTags($tags);
$page->setStatusCode($status_code);
return $page;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment