Render this view for a certain display.
Note: You should better use just the preview function if you want to render a view.
string $display_id: The machine name of the display, which should be rendered.
(string|NULL) Return the output of the rendered view or NULL if something failed in the process.
public function render($display_id = NULL) {
$this
->execute($display_id);
// Check to see if the build failed.
if (!empty($this->build_info['fail'])) {
return;
}
if (!empty($this->build_info['denied'])) {
return;
}
drupal_theme_initialize();
$config = config('views.settings');
$exposed_form = $this->display_handler
->getPlugin('exposed_form');
$exposed_form
->pre_render($this->result);
$module_handler = \Drupal::moduleHandler();
// Check for already-cached output.
if (!empty($this->live_preview)) {
$cache = FALSE;
}
else {
$cache = $this->display_handler
->getPlugin('cache');
}
if ($cache && $cache
->cacheGet('output')) {
}
else {
if ($cache) {
$cache
->cacheStart();
}
// Run pre_render for the pager as it might change the result.
if (!empty($this->pager)) {
$this->pager
->pre_render($this->result);
}
// Initialize the style plugin.
$this
->initStyle();
if (!isset($this->response)) {
// Set the response so other parts can alter it.
$this->response = new Response('', 200);
}
// Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering.
if ($this->style_plugin
->usesFields()) {
foreach ($this->field as $id => $handler) {
if (!empty($this->field[$id])) {
$this->field[$id]
->pre_render($this->result);
}
}
}
$this->style_plugin
->pre_render($this->result);
// Let each area handler have access to the result set.
$areas = array(
'header',
'footer',
);
// Only call preRender() on the empty handlers if the result is empty.
if (empty($this->result)) {
$areas[] = 'empty';
}
foreach ($areas as $area) {
foreach ($this->{$area} as $handler) {
$handler
->preRender($this->result);
}
}
// Let modules modify the view just prior to rendering it.
$module_handler
->invokeAll('views_pre_render', array(
$this,
));
// Let the themes play too, because pre render is a very themey thing.
foreach ($GLOBALS['base_theme_info'] as $base) {
$module_handler
->invoke($base, 'views_pre_render', array(
$this,
));
}
$module_handler
->invoke($GLOBALS['theme'], 'views_pre_render', array(
$this,
));
$this->display_handler->output = $this->display_handler
->render();
if ($cache) {
$cache
->cacheSet('output');
}
}
$exposed_form
->post_render($this->display_handler->output);
if ($cache) {
$cache
->post_render($this->display_handler->output);
}
// Let modules modify the view output after it is rendered.
$module_handler
->invokeAll('views_post_render', array(
$this,
$this->display_handler->output,
$cache,
));
// Let the themes play too, because post render is a very themey thing.
foreach ($GLOBALS['base_theme_info'] as $base) {
$module_handler
->invoke($base, 'views_post_render', array(
$this,
));
}
$module_handler
->invoke($GLOBALS['theme'], 'views_post_render', array(
$this,
));
return $this->display_handler->output;
}