function module_implements

Determines which modules are implementing a hook.

Parameters

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

Return value

An array with the names of the modules which are implementing this hook.

See also

module_implements_write_cache()

Related topics

70 calls to module_implements()
aggregator_admin_form in drupal/core/modules/aggregator/aggregator.admin.inc
Form constructor for the aggregator system settings.
ConfigStorageController::attachLoad in drupal/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
Attaches data to entities upon loading.
DatabaseStorageController::attachLoad in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
Attaches data to entities upon loading.
DatabaseStorageControllerNG::attachLoad in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Overrides DatabaseStorageController::attachLoad().
DrupalUnitTestBaseTest::testSetUp in drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
Tests expected behavior of setUp().

... See full list

4 string references to 'module_implements'
ModuleApiTest::testModuleImplements in drupal/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php
Test module_implements() caching.
module_implements_reset in drupal/core/includes/module.inc
Regenerates the stored list of hook implementations.
module_implements_write_cache in drupal/core/includes/module.inc
Writes the hook implementation cache.
watchdog in drupal/core/includes/bootstrap.inc
Logs a system message.

File

drupal/core/includes/module.inc, line 805
API for loading and interacting with Drupal modules.

Code

function module_implements($hook) {

  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['implementations'] =& drupal_static(__FUNCTION__);
  }
  $implementations =& $drupal_static_fast['implementations'];

  // Fetch implementations from cache.
  if (empty($implementations)) {
    $implementations = cache('bootstrap')
      ->get('module_implements');
    if ($implementations === FALSE) {
      $implementations = array();
    }
    else {
      $implementations = $implementations->data;
    }
  }
  if (!isset($implementations[$hook])) {

    // The hook is not cached, so ensure that whether or not it has
    // implementations, that the cache is updated at the end of the request.
    $implementations['#write_cache'] = TRUE;
    $hook_info = module_hook_info();
    $implementations[$hook] = array();
    foreach (module_list() as $module) {
      $include_file = isset($hook_info[$hook]['group']) && module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);

      // Since module_hook() may needlessly try to load the include file again,
      // function_exists() is used directly here.
      if (function_exists($module . '_' . $hook)) {
        $implementations[$hook][$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') {
      drupal_alter('module_implements', $implementations[$hook], $hook);
    }
  }
  else {
    foreach ($implementations[$hook] as $module => $group) {

      // If this hook implementation is stored in a lazy-loaded file, so include
      // that file first.
      if ($group) {
        module_load_include('inc', $module, "{$module}.{$group}");
      }

      // It is possible that a module removed a hook implementation without the
      // implementations cache being rebuilt yet, so we check whether the
      // function exists on each request to avoid undefined function errors.
      // Since module_hook() may needlessly try to load the include file again,
      // function_exists() is used directly here.
      if (!function_exists($module . '_' . $hook)) {

        // Clear out the stale implementation from the cache and force a cache
        // refresh to forget about no longer existing hook implementations.
        unset($implementations[$hook][$module]);
        $implementations['#write_cache'] = TRUE;
      }
    }
  }
  return array_keys($implementations[$hook]);
}