diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 77dba8b..4684917 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -449,10 +449,6 @@ function drupal_theme_rebuild() { function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $result = array(); - $variable_process_phases = array( - 'preprocess functions' => 'preprocess', - ); - $hook_defaults = array( 'variables' => TRUE, 'render element' => TRUE, @@ -513,57 +509,54 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { } } - // Allow variable preprocessors for all theming hooks, whether the hook is - // implemented as a template or as a function. - foreach ($variable_process_phases as $phase_key => $phase) { - // Check for existing variable preprocessors. Ensure arrayness. - if (!isset($info[$phase_key]) || !is_array($info[$phase_key])) { - $info[$phase_key] = array(); - $prefixes = array(); - if ($type == 'module') { - // Default variable preprocessor prefix. - $prefixes[] = 'template'; - // Add all modules so they can intervene with their own variable - // preprocessors. This allows them to provide variable preprocessors - // even if they are not the owner of the current hook. - $prefixes = array_merge($prefixes, $module_list); - } - elseif ($type == 'theme_engine' || $type == 'base_theme_engine') { - // Theme engines get an extra set that come before the normally - // named variable preprocessors. - $prefixes[] = $name . '_engine'; - // The theme engine registers on behalf of the theme using the - // theme's name. - $prefixes[] = $theme; - } - else { - // This applies when the theme manually registers their own variable - // preprocessors. - $prefixes[] = $name; - } - foreach ($prefixes as $prefix) { - // Only use non-hook-specific variable preprocessors for theming - // hooks implemented as templates. See theme(). - if (isset($info['template']) && function_exists($prefix . '_' . $phase)) { - $info[$phase_key][] = $prefix . '_' . $phase; - } - if (function_exists($prefix . '_' . $phase . '_' . $hook)) { - $info[$phase_key][] = $prefix . '_' . $phase . '_' . $hook; - } - } + // Preprocess variables for all theming hooks, whether the hook is + // implemented as a template or as a function. Ensure they are arrays. + if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) { + $info['preprocess functions'] = array(); + $prefixes = array(); + if ($type == 'module') { + // Default variable preprocessor prefix. + $prefixes[] = 'template'; + // Add all modules so they can intervene with their own variable + // preprocessors. This allows them to provide variable preprocessors + // even if they are not the owner of the current hook. + $prefixes = array_merge($prefixes, $module_list); } - // Check for the override flag and prevent the cached variable - // preprocessors from being used. This allows themes or theme engines - // to remove variable preprocessors set earlier in the registry build. - if (!empty($info['override ' . $phase_key])) { - // Flag not needed inside the registry. - unset($result[$hook]['override ' . $phase_key]); + elseif ($type == 'theme_engine' || $type == 'base_theme_engine') { + // Theme engines get an extra set that come before the normally + // named variable preprocessors. + $prefixes[] = $name . '_engine'; + // The theme engine registers on behalf of the theme using the + // theme's name. + $prefixes[] = $theme; } - elseif (isset($cache[$hook][$phase_key]) && is_array($cache[$hook][$phase_key])) { - $info[$phase_key] = array_merge($cache[$hook][$phase_key], $info[$phase_key]); + else { + // This applies when the theme manually registers their own variable + // preprocessors. + $prefixes[] = $name; } - $result[$hook][$phase_key] = $info[$phase_key]; + foreach ($prefixes as $prefix) { + // Only use non-hook-specific variable preprocessors for theming + // hooks implemented as templates. See theme(). + if (isset($info['template']) && function_exists($prefix . '_preprocess')) { + $info['preprocess functions'][] = $prefix . '_preprocess'; + } + if (function_exists($prefix . '_preprocess_' . $hook)) { + $info['preprocess functions'][] = $prefix . '_preprocess_' . $hook; + } + } + } + // Check for the override flag and prevent the cached variable + // preprocessors from being used. This allows themes or theme engines + // to remove variable preprocessors set earlier in the registry build. + if (!empty($info['override preprocess functions'])) { + // Flag not needed inside the registry. + unset($result[$hook]['override preprocess functions']); + } + elseif (isset($cache[$hook]['preprocess functions']) && is_array($cache[$hook]['preprocess functions'])) { + $info['preprocess functions'] = array_merge($cache[$hook]['preprocess functions'], $info['preprocess functions']); } + $result[$hook]['preprocess functions'] = $info['preprocess functions']; } // Merge the newly created theme hooks into the existing cache. @@ -576,22 +569,20 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { foreach ($cache as $hook => $info) { // Check only if not registered by the theme or engine. if (empty($result[$hook])) { - foreach ($variable_process_phases as $phase_key => $phase) { - if (!isset($info[$phase_key])) { - $cache[$hook][$phase_key] = array(); - } - // Only use non-hook-specific variable preprocessors for theme hooks - // implemented as templates. See theme(). - if (isset($info['template']) && function_exists($name . '_' . $phase)) { - $cache[$hook][$phase_key][] = $name . '_' . $phase; - } - if (function_exists($name . '_' . $phase . '_' . $hook)) { - $cache[$hook][$phase_key][] = $name . '_' . $phase . '_' . $hook; - $cache[$hook]['theme path'] = $path; - } - // Ensure uniqueness. - $cache[$hook][$phase_key] = array_unique($cache[$hook][$phase_key]); + if (!isset($info['preprocess functions'])) { + $cache[$hook]['preprocess functions'] = array(); } + // Only use non-hook-specific variable preprocessors for theme hooks + // implemented as templates. See theme(). + if (isset($info['template']) && function_exists($name . '_preprocess')) { + $cache[$hook]['preprocess functions'][] = $name . '_preprocess'; + } + if (function_exists($name . '_preprocess_' . $hook)) { + $cache[$hook]['preprocess functions'][] = $name . '_preprocess_' . $hook; + $cache[$hook]['theme path'] = $path; + } + // Ensure uniqueness. + $cache[$hook]['preprocess functions'] = array_unique($cache[$hook]['preprocess functions']); } } } @@ -650,10 +641,8 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { // Optimize the registry to not have empty arrays for functions. foreach ($cache as $hook => $info) { - foreach (array('preprocess functions') as $phase) { - if (empty($info[$phase])) { - unset($cache[$hook][$phase]); - } + if (empty($info['preprocess functions'])) { + unset($cache[$hook]['preprocess functions']); } } return $cache; @@ -1029,13 +1018,9 @@ function theme($hook, $variables = array()) { } if (isset($info['preprocess functions'])) { $variables['theme_hook_suggestions'] = array(); - foreach (array('preprocess functions') as $phase) { - if (!empty($info[$phase])) { - foreach ($info[$phase] as $processor_function) { - if (function_exists($processor_function)) { - $processor_function($variables, $hook, $info); - } - } + foreach ($info['preprocess functions'] as $preprocessor_function) { + if (function_exists($preprocessor_function)) { + $preprocessor_function($variables, $hook, $info); } } // If the preprocess functions specified hook suggestions, and the