BlockController.php in Render cache 7.2
File
modules/controller/render_cache_block/src/RenderCache/Controller/BlockController.php
View source
<?php
namespace Drupal\render_cache_block\RenderCache\Controller;
use Drupal\render_cache\RenderCache\Controller\BaseRecursionController;
class BlockController extends BaseRecursionController {
protected function isCacheable(array $default_cache_info, array $context) {
return variable_get('render_cache_' . $this
->getPluginId() . '_' . $context['region'] . '_enabled', TRUE) && parent::isCacheable($default_cache_info, $context);
}
protected function getCacheContext($object, array $context) {
$block = $object;
$context = parent::getCacheContext($object, $context);
$context = $context + array(
'bid' => $block->bid,
'delta' => $block->delta,
'module' => $block->module,
);
return $context;
}
protected function getDefaultCacheInfo($context) {
$default_cache_info = parent::getDefaultCacheInfo($context);
$default_cache_info['render_cache_render_to_markup'] = TRUE;
return $default_cache_info;
}
protected function getCacheInfo($object, array $context) {
$block = $object;
$cache_info = parent::getCacheInfo($object, $context);
$cache_info['granularity'] = isset($block->cache) ? $block->cache : DRUPAL_NO_CACHE;
return $cache_info;
}
protected function getCacheKeys($object, array $context) {
$block = $object;
return array_merge(parent::getCacheKeys($object, $context), array(
$context['region'],
$context['module'],
$context['delta'],
));
}
protected function getCacheHash($object, array $context) {
$hash['module'] = $context['module'];
$hash['delta'] = $context['delta'];
if (!empty($context['context']->name)) {
$hash['context'] = $context['context']->name;
}
return $hash;
}
protected function getCacheTags($object, array $context) {
$tags = parent::getCacheTags($object, $context);
$tags[] = 'block:' . $context['id'];
return $tags;
}
protected function render(array $objects) {
$blocks = $objects;
module_load_include('module', 'block', 'block');
foreach ($blocks as $block) {
$block->cache = DRUPAL_NO_CACHE;
}
$list = _block_render_blocks($blocks);
$build = array();
if ($list) {
$build = _block_get_renderable_array($list);
}
return $build;
}
}