function HookCollectorPass::getAddableImplementations

Returns implementations suitable for adding in ModuleHandler::add().

This contains only procedural implementations, because the services for OOP implementations might not be available at this point.

This method is only to be used by ModuleHandler::add().

@todo Remove when ModuleHandler::add() is removed in Drupal 12.0.0.

@internal

Return value

array<string, array<string, callable-string>> Procedural implementations, as functions keyed by hook and module.

File

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

Class

HookCollectorPass
Collects and registers hook implementations.

Namespace

Drupal\Core\Hook

Code

public function getAddableImplementations() : array {
  $implementationsByHook = $this->getFilteredImplementations();
  // List of modules implementing hooks with the implementation details.
  $implementations = [];
  foreach ($implementationsByHook as $hook => $hookImplementations) {
    foreach ($this->modules as $module) {
      foreach (array_keys($hookImplementations, $module, TRUE) as $identifier) {
        if (!str_contains($identifier, '::')) {
          $implementations[$hook][$module] = $identifier;
        }
      }
    }
  }
  return $implementations;
}

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