function Registry::mergePreprocessFunctions

Same name in other branches
  1. 9 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::mergePreprocessFunctions()
  2. 8.9.x core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::mergePreprocessFunctions()
  3. 10 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 699

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

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;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.