Hi all, I just ran into this issue the other day. It seems that blocks that are not output on all pages do not trigger template_preprocess_block. This goes for any block (not just custom ones)

To duplicate the bug, simply add a block (eg. powered by Drupal) to the page via admin/build/blocks, configure the block to only show on one or more (but not all) pages, and you will find that template_preprocess_block is not called for the block.

You can determine that like so:

function ngTheme_preprocess_block(&$vars) {
  dpm($vars);
}

If the block is set to output on all pages, then it is preprocessed.

Comments

mikemadison’s picture

I did a bit of initial testing on a clean Drupal 7.38 build. Nothing immediately jumps out at me in the changed files that would make this different in 7.37 vs. 7.38.

I used Bartik.

My code looked something like:

/**
 * Override or insert variables into the block template.
 */
function bartik_preprocess_block(&$variables) {
  dpm($variables);
  // In the header region visually hide block titles.
  if ($variables['block']->region == 'header') {
    $variables['title_attributes_array']['class'][] = 'element-invisible';
  }
}

Note that Bartik fully spells out $variables, vs. $vars. Not sure if this matters in your theme.

When I change powered by Drupal to be "Only the listed pages" I used front as my parameter, and the dpm still fires on the homepage.

Any other hints on what I might be doing differently than you are would be appreciated so I can try and repro.

derekwebb1’s picture

Hmmm... that is odd. I tried changing the theme to Bartik and adding the Powered by block to the front page only and I still do not see it going through the preprocess (while looking at front page - or any other page). Are you sure you set it to display only on the front? Thanks for looking at this as well!

derekwebb1’s picture

I have found that once in a blue moon, preprocess does seem to be firing for blocks that exist only on one or a few pages, however I am not able to discern why they work every now and then, but usually not. On an aside, using dpm to dump out the variables in template_preprocess_block in block module, tends to give me OOM errors (even though there are only three blocks on the page)

derekwebb1’s picture

I have tried this with Bartik and no custom module blocks on any page and the results are the same. Interestingly, blocks get the html_id and get rendered ok, even if they don't pass through block.module template_preprocess_block()... This is the strangest error I think I've ever seen with Drupal.

derekwebb1’s picture

Just found out that node preprocessing is not working on my site either... I am running very few modules, and the names are correct. I had been running panels and panelizer but I uninstalled them earlier.

Version: 7.37 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.