You can simply toggle the $show_block variable if you do not want to recreate all functionality done in the various preprocessor hooks around the place:

<?php
/**
 * Implementation of hook_theme_registry_alter().
 *
 * This adds the new preprocess function onto the theme stack, but at the start
 * so it is called before the problematic template_preprocess_page() function.
 */
function HOOK_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'HOOK');
  if (isset($theme_registry['page']) && isset($theme_registry['page']['theme paths'])) {
    array_unshift($theme_registry['page']['theme paths'], $path);
    array_unshift($theme_registry['page']['preprocess functions'], 'HOOK_pre_preprocess_page');
  }
}

/**
 * Toogle the block flag here :)
 */
function HOOK_pre_preprocess_page(&$variables) {
  // Set additional conditions to change $show_blocks if you want here...
  $is404 = $_GET['q'] == drupal_get_normal_path(variable_get('site_404', ''));
  $is403 = $_GET['q'] == drupal_get_normal_path(variable_get('site_403', ''));
  $variables['show_blocks'] = ($is404 || $is403) ? true : $variables['show_blocks'];
}
?>

And that would be enough to force blocks to show!

PS: I think that you can still use $_REQUEST['q'] to get the original path 'q' / The installation or update script should be used to set any variables so the init() would not need to be called.

Comments

johnalbin’s picture

Title: Easier, more Drupal-like way » Simplify module by moving preprocess before template_preprocess_page

Dang! Why didn't I think of that? I've re-arranged preprocess functions before, too! :-p

Excellent suggestion! This should also make the module compatible with all themes.

johnalbin’s picture

Status: Active » Fixed

Wrote it, tested it, committed it!

Thanks again, Alan!

alan d.’s picture

No worries. Glad to help

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.