? parent_preprocess.patch Index: STARTERKIT/template.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/themes/zen/STARTERKIT/template.php,v retrieving revision 1.9 diff -u -p -r1.9 template.php --- STARTERKIT/template.php 21 Apr 2008 17:01:54 -0000 1.9 +++ STARTERKIT/template.php 29 Apr 2008 21:37:25 -0000 @@ -58,8 +58,8 @@ if (theme_get_setting('STARTERKIT_fixed' */ /* -- Delete this line if you want to use this function function STARTERKIT_preprocess(&$vars, $hook) { - // First run Zen's preprocess function. - phptemplate_preprocess($vars); + // First run the parent theme's preprocess functions. + zen_parent_preprocess('STARTERKIT', $vars, $hook); $vars['sample_variable'] = t('Lorem ipsum.'); } @@ -72,9 +72,7 @@ function STARTERKIT_preprocess(&$vars, $ * A sequential array of variables to pass to the theme template. */ /* -- Delete this line if you want to use this function -function STARTERKIT_preprocess_page(&$vars) { - // First run Zen's preprocess function. - phptemplate_preprocess_page($vars); +function STARTERKIT_preprocess_page(&$vars, $hook) { $vars['sample_variable'] = t('Lorem ipsum.'); } @@ -87,9 +85,7 @@ function STARTERKIT_preprocess_page(&$va * A sequential array of variables to pass to the theme template. */ /* -- Delete this line if you want to use this function -function STARTERKIT_preprocess_node(&$vars) { - // First run Zen's preprocess function. - phptemplate_preprocess_node($vars); +function STARTERKIT_preprocess_node(&$vars, $hook) { $vars['sample_variable'] = t('Lorem ipsum.'); } @@ -102,9 +98,7 @@ function STARTERKIT_preprocess_node(&$va * A sequential array of variables to pass to the theme template. */ /* -- Delete this line if you want to use this function -function STARTERKIT_preprocess_comment(&$vars) { - // First run Zen's preprocess function. - phptemplate_preprocess_comment($vars); +function STARTERKIT_preprocess_comment(&$vars, $hook) { $vars['sample_variable'] = t('Lorem ipsum.'); } @@ -117,9 +111,7 @@ function STARTERKIT_preprocess_comment(& * A sequential array of variables to pass to the theme template. */ /* -- Delete this line if you want to use this function -function STARTERKIT_preprocess_block(&$vars) { - // First run Zen's preprocess function. - phptemplate_preprocess_block($vars); +function STARTERKIT_preprocess_block(&$vars, $hook) { $vars['sample_variable'] = t('Lorem ipsum.'); } Index: zen/template.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/themes/zen/zen/template.php,v retrieving revision 1.13 diff -u -p -r1.13 template.php --- zen/template.php 21 Apr 2008 17:03:03 -0000 1.13 +++ zen/template.php 29 Apr 2008 21:37:25 -0000 @@ -92,7 +92,7 @@ function phptemplate_breadcrumb($breadcr * @param $vars * A sequential array of variables to pass to the theme template. */ -function phptemplate_preprocess(&$vars) { +function zen_preprocess(&$vars, $hook) { global $user; // Set a new $is_admin variable. This is determined by looking at the @@ -112,7 +112,7 @@ function phptemplate_preprocess(&$vars) * @param $vars * A sequential array of variables to pass to the theme template. */ -function phptemplate_preprocess_page(&$vars) { +function zen_preprocess_page(&$vars, $hook) { global $theme; // These next lines add additional CSS files and redefine @@ -179,7 +179,7 @@ function phptemplate_preprocess_page(&$v * @param $vars * A sequential array of variables to pass to the theme template. */ -function phptemplate_preprocess_node(&$vars) { +function zen_preprocess_node(&$vars, $hook) { global $user; // Special classes for nodes @@ -213,7 +213,7 @@ function phptemplate_preprocess_node(&$v * @param $vars * A sequential array of variables to pass to the theme template. */ -function phptemplate_preprocess_comment(&$vars) { +function zen_preprocess_comment(&$vars, $hook) { global $user; // We load the node object that the current comment is attached to @@ -262,7 +262,7 @@ function phptemplate_preprocess_comment( * @param $vars * A sequential array of variables to pass to the theme template. */ -function phptemplate_preprocess_block(&$vars) { +function zen_preprocess_block(&$vars, $hook) { $block = $vars['block']; // Special classes for blocks @@ -373,3 +373,48 @@ function path_to_zentheme() { } return $theme_path; } + +/** + * Call a parent theme's preprocess function. + * + * By default, a sub-theme's preprocess function will be called in place of the + * parent theme's, rather than in addition to. By calling this function as the + * first line of a preprocess function, you can easily make the effect additive. + * + * In order to leverage this function, in your own themename_preprocess() + * function you must do two things: + * + * - You must accept the second $hook parameter. + * - You must specify the following as the very first line of the function: + * + * zen_parent_preprocess('NAME_OF_YOUR_THEME', $vars, $hook); + * + * As long as the theme you are inheriting from does so as well, preprocess + * functions will inherit all the way up the chain. + * + * @param string $theme + * The name of the theme that is calling this function. + * @param $vars + * The array of template variables. + * @param string $hook + * The hook that we are preprocessing. + */ +function zen_parent_preprocess($theme, &$vars, $hook) { + + $themes = list_themes(); + + if (!empty($themes[$theme]->base_theme)) { + + $functions = array( + $themes[$theme]->base_theme . '_preprocess', + $themes[$theme]->base_theme . '_preprocess_' . $hook, + ); + + // Call the parent theme if possible. + foreach ($functions as $function) { + if (function_exists($function)) { + $function($vars, $hook); + } + } + } +}