PageController.php in Render cache 7.2
File
modules/controller/render_cache_page/src/RenderCache/Controller/PageController.php
View source
<?php
namespace Drupal\render_cache_page\RenderCache\Controller;
use Drupal\render_cache\RenderCache\Controller\BaseController;
class PageController extends BaseController implements PageControllerInterface {
public function hook_init() {
$this->renderStack
->increaseRecursion();
}
public function view(array $objects) {
foreach ($objects as $id => $page) {
if (!is_array($page->content)) {
$page->content = array(
'main' => array(
'#markup' => $page->content,
),
);
}
$storage = $this->renderStack
->decreaseRecursion();
$page->content['x_render_cache_page_recursion_storage'] = $storage;
}
return parent::view($objects);
}
protected function getDefaultCacheInfo($context) {
$default_cache_info = parent::getDefaultCacheInfo($context);
$default_cache_info['granularity'] = DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE;
$default_cache_info['render_cache_cache_strategy'] = \RenderCache::RENDER_CACHE_STRATEGY_DIRECT_RENDER;
$default_cache_info['render_cache_preserve_original'] = TRUE;
return $default_cache_info;
}
protected function isCacheable(array $default_cache_info, array $context) {
return variable_get('render_cache_' . $this
->getPluginId() . '_' . $context['page_callback'] . '_enabled', FALSE) && parent::isCacheable($default_cache_info, $context);
}
protected function getCacheKeys($object, array $context) {
return array_merge(parent::getCacheKeys($object, $context), array(
$context['page_callback'],
));
}
protected function getCacheHash($object, array $context) {
$hash['expiration'] = round(time() / 3600);
return $hash;
}
protected function getCacheTags($object, array $context) {
$tags = parent::getCacheTags($object, $context);
$tags[] = 'theme_global_settings';
return $tags;
}
protected function render(array $objects) {
foreach ($objects as $id => $page) {
if ($this->renderStack
->supportsDynamicAssets()) {
$storage = $page->content['x_render_cache_page_recursion_storage'];
unset($page->content['x_render_cache_page_recursion_storage']);
$this->renderStack
->addRecursionStorage($storage, TRUE);
}
$build[$id] = render_cache_page_drupal_render_page_helper($page->content);
}
global $theme;
$page_id = current(array_keys($objects));
$build[$page_id]['#cache']['tags'][] = 'theme:' . $theme;
return $build;
}
}
Classes
Name |
Description |
PageController |
PageController - Provides render caching for page objects. |