function HookCollectorPass::collectAllHookImplementations

Collects all hook implementations.

@internal This method is only used by ModuleHandler.

@todo Pass only $container when ModuleHandler->add is removed https://www.drupal.org/project/drupal/issues/3481778

Parameters

array $module_filenames: An associative array. Keys are the module names, values are relevant info yml file path.

Symfony\Component\DependencyInjection\ContainerBuilder|null $container: The container.

Return value

static A HookCollectorPass instance holding all hook implementations and include file information.

2 calls to HookCollectorPass::collectAllHookImplementations()
HookCollectorPass::process in core/lib/Drupal/Core/Hook/HookCollectorPass.php
ModuleHandler::add in core/lib/Drupal/Core/Extension/ModuleHandler.php
Adds a module or profile to the list of currently active modules.

File

core/lib/Drupal/Core/Hook/HookCollectorPass.php, line 140

Class

HookCollectorPass
Collects and registers hook implementations.

Namespace

Drupal\Core\Hook

Code

public static function collectAllHookImplementations(array $module_filenames, ?ContainerBuilder $container = NULL) : static {
    $modules = array_map(fn($x) => preg_quote($x, '/'), array_keys($module_filenames));
    // Longer modules first.
    usort($modules, fn($a, $b) => strlen($b) - strlen($a));
    $module_preg = '/^(?<function>(?<module>' . implode('|', $modules) . ')_(?!preprocess_)(?!update_\\d)(?<hook>[a-zA-Z0-9_\\x80-\\xff]+$))/';
    $collector = new static();
    foreach ($module_filenames as $module => $info) {
        $skip_procedural = FALSE;
        if ($container?->hasParameter("{$module}.hooks_converted")) {
            $skip_procedural = $container->getParameter("{$module}.hooks_converted");
        }
        $collector->collectModuleHookImplementations(dirname($info['pathname']), $module, $module_preg, $skip_procedural);
    }
    return $collector;
}

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