Allow subthemes to have preprocess hooks without tpl files.
| Project: | Zen |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Buried in the D6 theme guide is this note:
In order for your theme to have its preprocessors recognized, the template associated with the hook must exist inside the theme. When a default template exists, copy it to your theme and clear the registry.
This would mean that a sub-theme would have to have copy of all of Zen core’s .tpl.php files. Unless we can figure out a better way to handle it.
When I talked to Earl about this, he said…
Hmm, in D6 you'd implement hook_theme, run the auto discovery function and get its results; then do your own check for theme_* functions. If the hook was already discovered, ignore it; if it wasn't, add it to your list and make sure you keep path information
…which I will have to translate into actual code and play around with.

#1
Initial notes:
<?phpfunction zen_theme($existing, $type, $theme) {
$new['page'] = $existing['page'];
$new['node'] = $existing['node'];
$new['comment'] = $existing['comment'];
$new['block'] = $existing['block'];
$new['block']['preprocess functions'][] = 'zen_preprocess_block'; // If we change phptemplate_preprocess_block to zen_preprocess_block
return $new;
}
?>
#2
I am going to show my ignorance here. What would happen if Zen always had a sub-theme and was factored for that?
#3
Ok. I tried to return the preprocess functions from a HOOK_theme() call, but _theme_process_registry() sees the new SUBTHEME_preprocess_HOOK function, looks for a HOOK.tpl.php in the subtheme and, when it doesn't find it, assumes you must want to use a SUBTHEME_HOOK() function to build the template. And, thus, it all falls apart.
The documention for HOOK_theme shows this:
<?phpfunction SUBTHEME_theme($existing, $type, $theme, $path) {}
?>
Fortunately, I discovered that if I implement it like so:
<?phpfunction SUBTHEME_theme(&$existing, $type, $theme, $path) {}
?>
I can manipulate the registry cache ($existing) directly. Sweet. Not sure if I'm abusing the HOOK_theme() call, but its the only way to fix this issue.
I'm attaching the patch for reference.
#4
Committed.
#5
Right now, the patch allows sub-themes to have preprocess functions for any of the preprocess functions used in the base Zen theme (page, node, block, comment). But I think it would be good to expand this to allow preprocess functions for any HOOK that has a tpl file (regardless if the tpl is in the Zen theme or not.)
#6
Ok. I've optimized the code and expanded it to apply preprocess functions to ALL hooks, not just the four used in zen's template.php page.
#7
Hey JohnAlbin, could you attach your updated patch?
#8
The patch in #6 is available here: http://cvs.drupal.org/viewvc.py/drupal/contributions/themes/zen/zen/temp...
Of course, it patches the code that was patched in #4. If you want the entire code, the heart of the patch is the HOOK_theme() hook function; you can find the entire hook (called zen_theme, of course) in zen/template.php in the 6.x-1.0-beta1 release.
#9
Automatically closed -- issue fixed for two weeks with no activity.