diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 9589f57..ab64409 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -583,17 +583,24 @@ protected function postProcessExtension(array &$cache, $theme) { } $prefixes[] = $theme->getName(); - // Collect all known hooks. Discovered functions must be based on a known - // hook. - $hooks = implode('|', array_keys($cache)); - // Collect all variable processor functions in the correct order. $processors = []; + $matches = []; + // Look for functions named according to the pattern and add them if they + // have matching hooks in the registry. foreach ($prefixes as $prefix) { // Grep only the functions which are within the prefix group. list($first_prefix,) = explode('_', $prefix, 2); - if (isset($grouped_functions[$first_prefix])) { - $processors += preg_grep("/^{$prefix}_preprocess_($hooks)(__)?/", $grouped_functions[$first_prefix]); + if (!isset($grouped_functions[$first_prefix])) { + continue; + } + + foreach ($grouped_functions[$first_prefix] as $candidate) { + if (preg_match("/^{$prefix}_preprocess_(.*)(__)?/", $candidate, $matches)) { + if (isset($cache[$matches[1]])) { + $processors[] = $candidate; + } + } } }