module_implements

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 6 module_implements($hook, $sort = FALSE, $refresh = FALSE)
7 module_implements($hook, $sort = FALSE, $reset = FALSE)
8 module_implements($hook, $sort = FALSE)

Determine which modules are implementing a hook.

Parameters

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

$sort By default, modules are ordered by weight and filename, settings this option to TRUE, module list will be ordered by module name.

$reset For internal use only: Whether to force the stored list of hook implementations to be regenerated (such as after enabling a new module, before processing hook_enable).

Return value

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

See also

module_implements_write_cache()

Related topics

▾ 66 functions call module_implements()

aggregator_admin_form in modules/aggregator/aggregator.admin.inc
Form builder; Configure the aggregator system.
block_form_system_performance_settings_alter in modules/block/block.module
Implements hook_form_FORM_ID_alter().
DrupalDefaultEntityController::attachLoad in includes/entity.inc
Attaches data to entities upon loading. This will attach fields, if the entity is fieldable. It calls hook_entity_load() for modules which need to add data to all entities. It also calls hook_TYPE_load() on the loaded entities. For…
DrupalWebTestCase::tearDown in modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
drupal_alter in includes/module.inc
Hands off alterable variables to type-specific *_alter implementations.
drupal_cron_run in includes/common.inc
Executes a cron run when called.
drupal_get_complete_schema in includes/bootstrap.inc
Get the whole database schema.
drupal_get_filetransfer_info in includes/common.inc
Drupal FileTransfer registry.
drupal_get_normal_path in includes/path.inc
Given a path alias, return the internal path it represents.
drupal_render_page in includes/common.inc
Renders the page, including all theming.
field_access in modules/field/field.module
Determine whether the user has access to a given field.
field_attach_form in modules/field/field.attach.inc
Add form elements for all fields for an entity to a form structure.
field_attach_insert in modules/field/field.attach.inc
Save field data for a new entity.
field_attach_load in modules/field/field.attach.inc
Loads fields for the current revisions of a group of entities.
field_attach_submit in modules/field/field.attach.inc
Perform necessary operations on field data submitted by a form.
field_attach_update in modules/field/field.attach.inc
Save field data for an existing entity.
field_attach_validate in modules/field/field.attach.inc
Perform field validation against the field data in an entity.
field_help in modules/field/field.module
Implements hook_help().
field_purge_data in modules/field/field.crud.inc
Purges the field data for a single field on a single pseudo-entity.
field_update_field in modules/field/field.crud.inc
Updates a field.
file_download in includes/file.inc
Menu handler for private file transfers.
file_file_download in modules/file/file.module
Implements hook_file_download().
filter_get_filters in modules/filter/filter.module
Return a list of all filters provided by modules.
help_links_as_list in modules/help/help.admin.inc
help_menu in modules/help/help.module
Implements hook_menu().
image_effect_definitions in modules/image/image.module
Pull in image effects exposed by modules implementing hook_image_effect_info().
image_styles in modules/image/image.module
Get an array of all styles and their settings.
LocaleLanguageNegotiationInfoFunctionalTest::languageNegotiationUpdate in modules/locale/locale.test
Update language types/negotiation information.
menu_get_active_help in includes/menu.inc
Returns the help associated with the active menu item.
menu_router_build in includes/menu.inc
Collect and alter the menu definitions.
ModuleUnitTest::testModuleImplements in modules/simpletest/tests/module.test
Test module_implements() caching.
module_disable in includes/module.inc
Disable a given set of modules.
module_enable in includes/module.inc
Enables or installs a given list of modules.
module_invoke_all in includes/module.inc
Invoke a hook in all enabled modules that implement it.
node_access in modules/node/node.module
Determine whether the current user may perform the given operation on the specified node.
node_access_rebuild in modules/node/node.module
Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.
node_access_view_all_nodes in modules/node/node.module
Determines whether the user has a global viewing grant for all nodes.
node_access_write_grants in modules/node/node.module
Writes a list of grants to the database, deleting any previously saved ones.
node_form_submit_build_node in modules/node/node.pages.inc
Updates the form state's node entity by processing this submission's values.
node_modules_enabled in modules/node/node.module
Implements hook_modules_enabled().
node_requirements in modules/node/node.module
Implements hook_requirements().
node_validate in modules/node/node.module
Perform validation checks on the given node.
rdf_install in modules/rdf/rdf.install
Implements hook_install().
search_get_info in modules/search/search.module
Returns information about available search modules.
search_invoke_preprocess in modules/search/search.module
Invokes hook_search_preprocess() in modules.
shortcut_set_delete_form in modules/shortcut/shortcut.admin.inc
Form callback: builds the confirmation form for deleting a shortcut set.
system_install in modules/system/system.install
Implements hook_install().
system_modules in modules/system/system.admin.inc
Menu callback; provides module enable/disable interface.
UpgradePathTestCase::performUpgrade in modules/simpletest/tests/upgrade/upgrade.test
Perform the upgrade.
UpgradePathTestCase::tearDown in modules/simpletest/tests/upgrade/upgrade.test
Override of DrupalWebTestCase::tearDown() specialized for upgrade testing.
user_admin_permissions in modules/user/user.admin.inc
Menu callback: administer permissions.
user_filters in modules/user/user.module
List user administration filters that can be applied.
user_module_invoke in modules/user/user.module
Invokes a user hook in every module.
user_permission_get_modules in modules/user/user.module
Determine the modules that permissions belong to.
watchdog in includes/bootstrap.inc
Log a system message.
watchdog_skip_semaphore in modules/simpletest/tests/actions_loop_test.module
Replacement of the watchdog() function that eliminates the use of semaphores so that we can test the abortion of an action loop.
_block_rehash in modules/block/block.module
Update the 'block' DB table with the blocks currently exported by modules.
_block_render_blocks in modules/block/block.module
Render the content and subject for a set of blocks.
_field_info_collate_types in modules/field/field.info.inc
Collates all information on field types, widget types and related structures.
_node_query_node_access_alter in modules/node/node.module
Helper for node access functions.
_node_types_build in modules/node/node.module
Builds and returns the list of available node types.
_rdf_get_default_mapping in modules/rdf/rdf.module
Helper function to get the default RDF mapping for a given entity type.
_registry_update in includes/registry.inc
Does the work for registry_update().
_system_date_format_types_build in modules/system/system.module
Builds and returns information about available date types.
_system_update_bootstrap_status in modules/system/system.module
Refresh bootstrap column in the system table.
_theme_build_registry in includes/theme.inc
Build the theme registry cache.

Code

includes/module.inc, line 631

<?php
function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  // 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'];

  // We maintain a persistent cache of hook implementations in addition to the
  // static cache to avoid looping through every module and every hook on each
  // request. Benchmarks show that the benefit of this caching outweighs the
  // additional database hit even when using the default database caching
  // backend and only a small number of modules are enabled. The cost of the
  // cache_get() is more or less constant and reduced further when non-database
  // caching backends are used, so there will be more significant gains when a
  // large number of modules are installed or hooks invoked, since this can
  // quickly lead to module_hook() being called several thousand times
  // per request.
  if ($reset) {
    $implementations = array();
    cache_set('module_implements', array(), 'cache_bootstrap');
    drupal_static_reset('module_hook_info');
    drupal_static_reset('drupal_alter');
    cache_clear_all('hook_info', 'cache_bootstrap');
    return;
  }

  // Fetch implementations from cache.
  if (empty($implementations)) {
    $implementations = cache_get('module_implements', 'cache_bootstrap');
    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();
    $list = module_list(FALSE, FALSE, $sort);
    foreach ($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]);
}
?>