W3cubDocs

/Drupal 8

protected function ModuleHandler::buildImplementationInfo

protected ModuleHandler::buildImplementationInfo($hook)

Builds hook implementation information for a given hook name.

Parameters

string $hook: The name of the hook (e.g. "help" or "menu").

Return value

mixed[] An array whose keys are the names of the modules which are implementing this hook and whose values are either a string identifying a file in which the implementation is to be found, or FALSE, if the implementation is in the module file.

Throws

\RuntimeException Exception thrown when an invalid implementation is added by hook_module_implements_alter().

See also

\Drupal\Core\Extension\ModuleHandler::getImplementationInfo()

File

core/lib/Drupal/Core/Extension/ModuleHandler.php, line 563

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

protected function buildImplementationInfo($hook) {
  $implementations = array();
  $hook_info = $this->getHookInfo();
  foreach ($this->moduleList as $module => $extension) {
    $include_file = isset($hook_info[$hook]['group']) && $this->loadInclude($module, 'inc', $module . '.' . $hook_info[$hook]['group']);
    // Since $this->implementsHook() may needlessly try to load the include
    // file again, function_exists() is used directly here.
    if (function_exists($module . '_' . $hook)) {
      $implementations[$module] = $include_file ? $hook_info[$hook]['group'] : FALSE;
    }
  }
  // Allow modules to change the weight of specific implementations, but avoid
  // an infinite loop.
  if ($hook != 'module_implements_alter') {
    // Remember the original implementations, before they are modified with
    // hook_module_implements_alter().
    $implementations_before = $implementations;
    // Verify implementations that were added or modified.
    $this->alter('module_implements', $implementations, $hook);
    // Verify new or modified implementations.
    foreach (array_diff_assoc($implementations, $implementations_before) as $module => $group) {
      // If drupal_alter('module_implements') changed or added a $group, the
      // respective file needs to be included.
      if ($group) {
        $this->loadInclude($module, 'inc', "$module.$group");
      }
      // If a new implementation was added, verify that the function exists.
      if (!function_exists($module . '_' . $hook)) {
        throw new \RuntimeException("An invalid implementation {$module}_{$hook} was added by hook_module_implements_alter()");
      }
    }
  }
  return $implementations;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!ModuleHandler.php/function/ModuleHandler::buildImplementationInfo/8.1.x