Skip to content
Snippets Groups Projects
Commit 88ed5dce authored by Angie Byron's avatar Angie Byron
Browse files

#258089 by merlinofchaos and dvessel: Allow themes to have preprocess...

#258089 by merlinofchaos and dvessel: Allow themes to have preprocess functions without a corresponding .tpl.php file.
parent 72cd8d63
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -279,6 +279,7 @@ function drupal_theme_rebuild() {
* over how and when the preprocess functions are run.
*/
function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result = array();
$function = $name . '_theme';
if (function_exists($function)) {
$result = $function($cache, $type, $theme, $path);
......@@ -368,6 +369,26 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
// Merge the newly created theme hooks into the existing cache.
$cache = array_merge($cache, $result);
}
// Let themes have preprocess functions even if they didn't register a template.
if ($type == 'theme' || $type == 'base_theme') {
foreach ($cache as $hook => $info) {
// Check only if it's a template and not registered by the theme or engine
if (!empty($info['template']) && empty($result[$hook])) {
if (!isset($info['preprocess functions'])) {
$cache[$hook]['preprocess functions'] = array();
}
if (function_exists($name . '_preprocess')) {
$cache[$hook]['preprocess functions'][] = $name . '_preprocess';
}
if (function_exists($name . '_preprocess_' . $hook)) {
$cache[$hook]['preprocess functions'][] = $name . '_preprocess_' . $hook;
}
// Ensure uniqueness.
$cache[$hook]['preprocess functions'] = array_unique($cache[$hook]['preprocess functions']);
}
}
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment