class render_cache_hijack_context_reaction_block in Render cache 7.2
Same name and namespace in other branches
- 7 modules/render_cache_context/context/plugins/render_cache_hijack_context_reaction_block.inc \render_cache_hijack_context_reaction_block
Hierarchy
- class \context_reaction
Expanded class hierarchy of render_cache_hijack_context_reaction_block
2 string references to 'render_cache_hijack_context_reaction_block'
- render_cache_context_context_plugins in modules/
utility/ render_cache_context/ render_cache_context.module - Implementation of hook_context_plugins().
- render_cache_context_context_registry_alter in modules/
utility/ render_cache_context/ render_cache_context.module - Implements hook_context_registry_alter().
File
- modules/
utility/ render_cache_context/ context/ plugins/ render_cache_hijack_context_reaction_block.inc, line 3
View source
class render_cache_hijack_context_reaction_block extends context_reaction_block {
/**
* {@inheritdoc}
*/
function block_get_blocks_by_region($region) {
module_load_include('module', 'block', 'block');
// renderBlockList returns a render array() already,
// so no need to call _block_get_renderable_array().
$build = $this
->renderBlockList($region);
if ($this
->is_editable_region($region)) {
$build = $this
->editable_region($region, $build);
}
return $build;
}
/**
* Support the optional aggressive block list caching.
*
* Otherwise system_cron() clears context cache and parent::get_blocks()
* runs _block_rehash(), which is slow, every 30 minutes.
*
* @param string|null $region
* @param object|null $context
* @param bool $reset
*
* @return array|bool
*/
function get_blocks($region = NULL, $context = NULL, $reset = FALSE) {
if (!variable_get('render_cache_cache_block_list', TRUE)) {
return parent::get_blocks($region, $context, $reset);
}
$hash = md5(serialize(array(
$region,
$context,
)));
$cid = "render_cache:context_reaction_block:block_list:{$hash}";
if (!$reset) {
$cache = cache_get($cid);
if (!empty($cache->data)) {
return $cache->data;
}
}
$blocks = parent::get_blocks($region, $context, $reset);
cache_set($cid, $blocks);
return $blocks;
}
/**
* A caching version of block_list() plus _block_get_renderable_array().
*
* This function is identical to context_reaction_block::block_list()
* except that $this->renderBlocks() is called instead of
* _block_render_blocks() and that the sorting is done earlier.
*
* @see context_reaction_block::block_list().
*
* @param string $region
* The region to get blocks from.
*
* @return array
* A render array for this region. This render array will only contain
* #markup elements.
*/
protected function renderBlockList($region) {
module_load_include('module', 'block', 'block');
$context_blocks =& drupal_static('context_reaction_block_list');
$contexts = context_active_contexts();
if (!isset($context_blocks)) {
$info = $this
->get_blocks();
$context_blocks = array();
foreach ($contexts as $context) {
$options = $this
->fetch_from_context($context);
if (!empty($options['blocks'])) {
foreach ($options['blocks'] as $context_block) {
$bid = "{$context_block['module']}-{$context_block['delta']}";
if (isset($info[$bid])) {
$block = (object) array_merge((array) $info[$bid], $context_block);
$block->context = $context->name;
$block->title = isset($info[$block->bid]->title) ? $info[$block->bid]->title : NULL;
$block->cache = isset($info[$block->bid]->cache) ? $info[$block->bid]->cache : DRUPAL_NO_CACHE;
$context_blocks[$block->region][$block->bid] = $block;
}
}
}
}
$this
->is_editable_check($context_blocks);
global $theme;
$active_regions = $this
->system_region_list($theme);
foreach ($context_blocks as $r => $blocks) {
//only render blocks in an active region
if (array_key_exists($r, $active_regions)) {
// Sort blocks.
uasort($blocks, array(
'context_reaction_block',
'block_sort',
));
$context_blocks[$r] = $this
->renderBlocks($blocks, $r);
// Make blocks editable if allowed.
if ($this
->is_editable_region($r)) {
foreach ($context_blocks[$r] as $key => $block) {
$context_blocks[$r][$key] = $this
->editable_block($block);
}
}
}
}
}
return isset($context_blocks[$region]) ? $context_blocks[$region] : array();
}
protected function renderBlocks($context_blocks, $region) {
// Save the region to the $context.
$context = array(
'region' => $region,
);
// Convert the blocks array into the right format.
$blocks = array();
foreach ($context_blocks as $key => $block) {
$blocks["{$block->module}_{$block->delta}"] = $block;
}
// Delegate to render cache controller.
$rcc = render_cache_get_controller('block');
$rcc
->setContext($context);
$build = $rcc
->view($blocks);
return $build;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
function | Retrieve options from the context provided. | 1 | |
context_reaction:: |
function | Retrieve active contexts that have values for this reaction. | ||
context_reaction:: |
function | Clone our references when we're being cloned. | ||
context_reaction:: |
function | Constructor. Do not override. | ||
context_reaction_block:: |
function | An alternative version of block_list() that provides any context enabled blocks. | ||
context_reaction_block:: |
static | function | Sort callback. | |
context_reaction_block:: |
private | function | Allow modules to selectively allow ajax rendering of a specific block | |
context_reaction_block:: |
protected | function | Add markup for making a block editable. | |
context_reaction_block:: |
protected | function | Add markup for making a region editable. | |
context_reaction_block:: |
function | Context editor form for blocks. | 1 | |
context_reaction_block:: |
function | Submit handler context editor form. | 1 | |
context_reaction_block:: |
function | Execute. | ||
context_reaction_block:: |
function | Determine if there is an active context editor block, and set a flag. We will set a flag so that we can make sure that blocks with empty content have some default content. This is needed so the save of the context inline editor does not remove the… | ||
context_reaction_block:: |
protected | function | Determine whether inline editing requirements are met and that the current user may edit. | |
context_reaction_block:: |
protected | function | Return a list of enabled regions for which blocks should be built. Split out into a separate method for easy overrides in extending classes. | 1 |
context_reaction_block:: |
protected | function | Compatibility wrapper around json_decode(). | |
context_reaction_block:: |
protected | function | Generate the safe weight range for a block being added to a region such that there are enough potential unique weights to support all blocks. | |
context_reaction_block:: |
function |
Options form. Overrides context_reaction:: |
1 | |
context_reaction_block:: |
function |
Options form submit handler. Overrides context_reaction:: |
1 | |
context_reaction_block:: |
function | Check or set whether a rebuild of the block info cache is needed. | ||
context_reaction_block:: |
function | Block renderer for AJAX requests. Triggered when $_GET['context_block'] is set. See ->execute() for how this is called. | ||
context_reaction_block:: |
function |
Settings form for variables. Overrides context_reaction:: |
||
context_reaction_block:: |
protected | function | Provide caching for system_region_list since it can get called frequently. Evaluate for removal once https://drupal.org/node/1873450 lands or system_region_list is otherwise cached in core | |
render_cache_hijack_context_reaction_block:: |
function |
Get a renderable array of a region containing all enabled blocks. Overrides context_reaction_block:: |
||
render_cache_hijack_context_reaction_block:: |
function |
Support the optional aggressive block list caching. Overrides context_reaction_block:: |
||
render_cache_hijack_context_reaction_block:: |
protected | function | A caching version of block_list() plus _block_get_renderable_array(). | |
render_cache_hijack_context_reaction_block:: |
protected | function |