public function BaseController::view in Render cache 7.2
Parameters
array $objects:
Return value
array
Overrides ControllerInterface::view
1 call to BaseController::view()
- PageController::view in modules/
controller/ render_cache_page/ src/ RenderCache/ Controller/ PageController.php
1 method overrides BaseController::view()
- PageController::view in modules/
controller/ render_cache_page/ src/ RenderCache/ Controller/ PageController.php
File
- src/
RenderCache/ Controller/ BaseController.php, line 93 - Contains \Drupal\render_cache\RenderCache\Controller\BaseController
Class
- BaseController
- Base class for Controller plugin objects.
Namespace
Drupal\render_cache\RenderCache\ControllerCode
public function view(array $objects) {
$object_order = array_keys($objects);
// Retrieve controller context.
$context = $this
->getContext();
// Get default cache info and allow modules to alter it.
$default_cache_info = $this
->getDefaultCacheInfo($context);
$this
->alter('default_cache_info', $default_cache_info, $context);
// Calculate cache info map.
$cache_info_map = $this
->getCacheInfoMap($objects, $context, $default_cache_info);
$build = $this->cache
->getMultiple($cache_info_map);
$build += $this
->getPlaceholders($objects, $cache_info_map, $context);
$remaining = array_diff_key($objects, $build);
// Render non-cached entities.
if (!empty($remaining)) {
$object_build = $this
->renderRecursive($remaining);
// @todo It is possible for modules to set the request to not cacheable, so
// check this again.
// @todo This conflicts with memcache stampede protection, will need to
// set empty cache entries instead.
//if ($this->isCacheable($default_cache_info, $context)) {
$this->cache
->setMultiple($object_build, $cache_info_map);
//}
$build += $object_build;
}
$return = array();
foreach ($object_order as $id) {
// This can happen when a block, e.g. is empty.
if (!isset($build[$id])) {
continue;
}
$render = $build[$id];
// Unset any remaining weight properties.
unset($render['#weight']);
$cache_info = $cache_info_map[$id];
if (!$this->renderStack
->isRecursive()) {
$this->renderStack
->processPostRenderCache($render, $cache_info);
}
// Store recursive storage and remove from render array.
$storage = $this->renderStack
->addRecursionStorage($render);
// @todo Use a #post_render function.
if (isset($render['#markup']) && (variable_get('render_cache_debug_output', FALSE) || variable_get('render_cache_debug_output_' . $this
->getPluginId(), FALSE) || !empty($cache_info['render_cache_debug_output']))) {
// @todo Move to helper function.
$prefix = '<!-- START RENDER ID: ' . $id . ' CACHE INFO: ' . "\n" . print_r($cache_info, TRUE);
$cache_hit = !empty($cache_info_map[$id]['cid']) && !isset($object_build[$id]) ? 'YES' : 'NO';
$prefix .= "\nCACHE_HIT: {$cache_hit}\n";
$full_storage = $storage;
$attached = $this->renderStack
->collectAttached($render);
if ($attached) {
$full_storage['#attached'] = $attached;
}
$attached = print_r($storage, TRUE);
$prefix .= "\nATTACHED: " . print_r($full_storage, TRUE) . "\n";
$prefix .= "\nHOOKS:\n";
$hook_prefix = 'render_cache_' . $this
->getPluginId() . '_';
foreach (array(
'default_cache_info',
'cache_info',
'keys',
'tags',
'hash',
'validate',
) as $hook) {
$prefix .= '* hook_' . $hook_prefix . $hook . "_alter()\n";
}
$prefix .= '-->';
$suffix = '<!-- END RENDER: ' . $id . ' -->';
$render['#markup'] = "\n{$prefix}\n" . $render['#markup'] . "\n{$suffix}\n";
}
$return[$id] = $render;
}
// If this is the main entry point.
if (!$this->renderStack
->isRecursive() && variable_get('render_cache_send_drupal_cache_tags', TRUE)) {
$storage = $this->renderStack
->getRecursionStorage();
if (!empty($storage['#cache']['tags'])) {
$header = implode(' ', $storage['#cache']['tags']);
// @todo ensure render_cache is the top module.
// Currently this header can be send multiple times.
drupal_add_http_header('X-Drupal-Cache-Tags', $header, TRUE);
}
}
return $return;
}