function Registry::collectModulePreprocess

Collect module implementations of a single hook.

Parameters

array $cache: The preprocess hook.

string $hook: The theme registry, as documented in \Drupal\Core\Theme\Registry::processExtension().

Return value

array A list of preprocess functions.

2 calls to Registry::collectModulePreprocess()
Registry::build in core/lib/Drupal/Core/Theme/Registry.php
Builds the theme registry cache.
Registry::processExtension in core/lib/Drupal/Core/Theme/Registry.php
Process a single implementation of hook_theme().

File

core/lib/Drupal/Core/Theme/Registry.php, line 984

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

protected function collectModulePreprocess(array &$cache, string $hook) : array {
    $preprocess_functions = [];
    // This is used so we can collect all preprocess functions in modules but
    // prevent them from being executed. Registry needs to cache preprocess
    // functions so we only want to gather the ones that exist, but we do not
    // want to execute them. Callable is not used so that preprocess
    // implementations are not executed.
    $this->moduleHandler
        ->invokeAllWith($hook, function (callable $callable, string $module) use ($hook, &$cache, &$preprocess_functions) {
        $function = $module . '_' . $hook;
        $cache[static::PREPROCESS_INVOKES][$function] = [
            'module' => $module,
            'hook' => $hook,
        ];
        $preprocess_functions[] = $function;
    });
    return $preprocess_functions;
}

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