diff --git a/modules/block/block.module b/modules/block/block.module
index 2977ca8..be39955 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -848,10 +848,19 @@ function block_block_list_alter(&$blocks) {
* An array of visible blocks as expected by drupal_render().
*/
function _block_render_blocks($region_blocks) {
- // Block caching is not compatible with node access modules. We also
- // preserve the submission of forms in blocks, by fetching from cache only
+ $cacheable = TRUE;
+
+ // We preserve the submission of forms in blocks, by fetching from cache only
// if the request method is 'GET' (or 'HEAD').
- $cacheable = !count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
+ if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
+ $cacheable = FALSE;
+ }
+ // Block caching is not usually compatible with node access modules, so by
+ // default it is disabled when node access modules exist. However, it can be
+ // allowed by using the variable 'block_cache_bypass_node_grants'.
+ elseif (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))) {
+ $cacheable = FALSE;
+ }
// Proceed to loop over all blocks in order to compute their respective cache
// identifiers; this allows us to do one single cache_get_multiple() call
@@ -1054,13 +1063,13 @@ function block_menu_delete($menu) {
* Implements hook_form_FORM_ID_alter().
*/
function block_form_system_performance_settings_alter(&$form, &$form_state) {
- $disabled = count(module_implements('node_grants'));
+ $disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants')));
$form['caching']['block_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Cache blocks'),
'#default_value' => variable_get('block_cache', FALSE),
'#disabled' => $disabled,
- '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') : NULL,
+ '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') . ' '. t('You can force block caching to be enabled by setting the block_cache_bypass_node_grants variable to TRUE, see the settings.php file.') : NULL,
'#weight' => -1,
);
}
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 580cc38..42926e1 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -433,6 +433,19 @@ ini_set('session.cookie_lifetime', 2000000);
# $conf['js_gzip_compression'] = FALSE;
/**
+ * Block caching:
+ *
+ * Block caching may not compatible with node access modules depending on
+ * how the original block cache policy is defined set by the module that
+ * provides the block. By default, block cache will be disabled when one or
+ * more modules implement the hook_node_grant() hook. If you consider block
+ * caching to be safe on your site, you can bypass this restriction and force
+ * block caching to the default policy (per block setting) by setting the
+ * following variable to TRUE.
+ */
+# $conf['block_cache_bypass_node_grants'] = TRUE;
+
+/**
* String overrides:
*
* To override specific strings on your site with or without enabling the Locale