Skip to content

Instantly share code, notes, and snippets.

@basvdheijden
Created June 28, 2016 14:04
Show Gist options
  • Save basvdheijden/5ade4bcf7f2ed3c2dded26fe441d6fe6 to your computer and use it in GitHub Desktop.
Save basvdheijden/5ade4bcf7f2ed3c2dded26fe441d6fe6 to your computer and use it in GitHub Desktop.
<?php
public function view(EntityInterface $node, $view_mode = 'full', $langcode = NULL) {
$page = $this->entityManager
->getViewBuilder($node->getEntityTypeId())
->view($node, $view_mode);
$page['#pre_render'][] = [$this, 'buildTitle'];
$page['#entity_type'] = $node->getEntityTypeId();
$page['#' . $page['#entity_type']] = $node;
$render_array = $page;
$render_context = new RenderContext();
$result = $this->renderer->executeInRenderContext($render_context, function() use (&$render_array) {
return $this->renderer->renderRoot($render_array);
});
$content = new HtmlResponse($result);
$content->addCacheableDependency($render_context);
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment