diff options
author | David Rothstein <drothstein@gmail.com> | 2015-10-12 14:19:06 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-10-12 14:19:06 -0400 |
commit | d2900abc52256190275b1ed7c3d75e88d14c48c4 (patch) | |
tree | 61ed24b84218492cfd793dcc17265433f3389ef4 /modules | |
parent | f09fb9ec7c506f12d7f2498faa1a3f3d51d16547 (diff) | |
download | brdo-d2900abc52256190275b1ed7c3d75e88d14c48c4.tar.gz brdo-d2900abc52256190275b1ed7c3d75e88d14c48c4.tar.bz2 |
Issue #1534490 by msonnabaum, bigjim, David_Rothstein, pounard, Dave Reid: Make block cache cids alterable
Diffstat (limited to 'modules')
-rw-r--r-- | modules/block/block.api.php | 25 | ||||
-rw-r--r-- | modules/block/block.module | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/modules/block/block.api.php b/modules/block/block.api.php index d7453b24b..e38f7d6ee 100644 --- a/modules/block/block.api.php +++ b/modules/block/block.api.php @@ -364,5 +364,30 @@ function hook_block_list_alter(&$blocks) { } /** + * Act on block cache ID (cid) parts before the cid is generated. + * + * This hook allows you to add, remove or modify the custom keys used to + * generate a block cache ID (by default, these keys are set to the block + * module and delta). These keys will be combined with the standard ones + * provided by drupal_render_cid_parts() to generate the final block cache ID. + * + * To change the cache granularity used by drupal_render_cid_parts(), this hook + * cannot be used; instead, set the 'cache' key in the block's definition in + * hook_block_info(). + * + * @params $cid_parts + * An array of elements used to build the cid. + * @param $block + * The block object being acted on. + * + * @see _block_get_cache_id() + */ +function hook_block_cid_parts_alter(&$cid_parts, $block) { + global $user; + // This example shows how to cache a block based on the user's timezone. + $cid_parts[] = $user->timezone; +} + +/** * @} End of "addtogroup hooks". */ diff --git a/modules/block/block.module b/modules/block/block.module index 48c80d766..fe04e9902 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -967,6 +967,7 @@ function _block_get_cache_id($block) { // Start with common sub-patterns: block identification, theme, language. $cid_parts[] = $block->module; $cid_parts[] = $block->delta; + drupal_alter('block_cid_parts', $cid_parts, $block); $cid_parts = array_merge($cid_parts, drupal_render_cid_parts($block->cache)); return implode(':', $cid_parts); |