protected function Registry::mergePreprocessFunctions in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::mergePreprocessFunctions()
Merges the source hook's preprocess functions into the destination hook's.
Parameters
string $destination_hook_name: The name of the hook to merge preprocess functions to.
string $source_hook_name: The name of the hook to merge preprocess functions from.
array $parent_hook: The parent hook if it exists. Either an incomplete hook from suggestions or a base hook.
array $cache: The theme registry, as documented in \Drupal\Core\Theme\Registry::processExtension().
1 call to Registry::mergePreprocessFunctions()
- Registry::completeSuggestion in core/
lib/ Drupal/ Core/ Theme/ Registry.php - Completes the definition of the requested suggestion hook.
File
- core/
lib/ Drupal/ Core/ Theme/ Registry.php, line 678
Class
- Registry
- Defines the theme registry service.
Namespace
Drupal\Core\ThemeCode
protected function mergePreprocessFunctions($destination_hook_name, $source_hook_name, $parent_hook, array &$cache) {
// If base hook exists clone of it for the preprocess function
// without a template.
// @see https://www.drupal.org/node/2457295
if (isset($cache[$source_hook_name]) && (!isset($cache[$source_hook_name]['incomplete preprocess functions']) || !isset($cache[$destination_hook_name]['incomplete preprocess functions']))) {
$cache[$destination_hook_name] = $parent_hook + $cache[$source_hook_name];
if (isset($parent_hook['preprocess functions'])) {
$diff = array_diff($parent_hook['preprocess functions'], $cache[$source_hook_name]['preprocess functions']);
$cache[$destination_hook_name]['preprocess functions'] = array_merge($cache[$source_hook_name]['preprocess functions'], $diff);
}
// If a base hook isn't set, this is the actual base hook.
if (!isset($cache[$source_hook_name]['base hook'])) {
$cache[$destination_hook_name]['base hook'] = $source_hook_name;
}
}
}