module_implements

Versions
4.6
module_implements($hook)
4.7
module_implements($hook, $sort = FALSE)
5 – 6
module_implements($hook, $sort = FALSE, $refresh = FALSE)
7
module_implements($hook, $sort = FALSE, $reset = FALSE)

Determine which modules are implementing a hook.

See also

module_implements_write_cache()

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.

Related topics

▾ 54 functions call module_implements()

block_form_system_performance_settings_alter in modules/block/block.module
Implement hook_form_FORM_ID_alter().
drupal_alter in includes/common.inc
Hands off alterable variables to type-specific *_alter implementations.
drupal_get_normal_path in includes/path.inc
Given a path alias, return the internal path it represents.
drupal_get_schema in includes/bootstrap.inc
Get the schema definition of a table, or the whole database schema.
drupal_render_page in includes/common.inc
Renders the page, including all theming.
field_attach_create_bundle in modules/field/field.attach.inc
Notify field.module that a new bundle was created.
field_attach_delete in modules/field/field.attach.inc
Delete field data for an existing object. This deletes all revisions of field data for the object.
field_attach_delete_bundle in modules/field/field.attach.inc
Notify field.module the a bundle was deleted.
field_attach_delete_revision in modules/field/field.attach.inc
Delete field data for a single revision of an existing object. The passed object must have a revision id attribute.
field_attach_form in modules/field/field.attach.inc
Add form elements for all fields for an object to a form structure.
field_attach_insert in modules/field/field.attach.inc
Save field data for a new object.
field_attach_load in modules/field/field.attach.inc
Load all fields for the most current version of each of a set of objects of a single object type.
field_attach_presave in modules/field/field.attach.inc
Perform necessary operations just before fields data get saved.
field_attach_query in modules/field/field.attach.inc
Retrieve objects matching a given set of conditions.
field_attach_rename_bundle in modules/field/field.attach.inc
Notify field.module that a bundle was renamed.
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 object.
field_attach_validate in modules/field/field.attach.inc
Perform field validation against the field data in an object.
field_multilingual_available_languages in modules/field/field.multilingual.inc
Collect the available languages for the given entity type and field.
field_purge_data in modules/field/field.crud.inc
Purge the field data for a single field on a single pseudo-object.
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
Implement 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.
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.
module_disable in includes/module.inc
Disable a given set of modules.
module_enable in includes/module.inc
Enable a given list of modules.
module_invoke_all in includes/module.inc
Invoke a hook in all enabled modules that implement it.
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
Determine whether the user has a global viewing grant for all nodes.
node_access_write_grants in modules/node/node.module
This function will write a list of grants to the database, deleting any pre-existing grants. If a realm is provided, it will only delete grants from that realm, but it will always delete a grant from the 'all' realm. Modules which utilize...
node_requirements in modules/node/node.module
Implement hook_requirements().
rdf_install in modules/rdf/rdf.install
Implements hook_install().
search_get_info in modules/search/search.module
Get information about all available search hooks.
search_invoke_preprocess in modules/search/search.module
Invokes hook_search_preprocess() in modules.
system_get_module_admin_tasks in modules/system/system.module
Generate a list of tasks offered by a specified module.
system_install in modules/system/system.install
Implement hook_install().
system_modules in modules/system/system.admin.inc
Menu callback; provides module enable/disable interface.
system_rebuild_module_data in modules/system/system.module
Rebuild, save, and return data about all currently available modules.
url in includes/common.inc
Generate a URL.
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 hook_user() in every module.
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
Collate all information on field types, widget types and related structures.
_rdf_get_default_mapping in modules/rdf/rdf.module
Returns the default RDF mapping for a given entity type.
_registry_rebuild in includes/registry.inc
@see registry_rebuild.
_system_date_format_types_build in modules/system/system.module
Builds and returns the list of available date types.
_theme_build_registry in includes/theme.inc
Rebuild the theme registry cache.

Code

includes/module.inc, line 368

<?php
function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  $implementations = &drupal_static(__FUNCTION__, array());

  // 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());
    drupal_static_reset('module_hook_info');
    drupal_static_reset('drupal_alter');
    cache_clear_all('hook_info', 'cache');
    return;
  }

  // Fetch implementations from cache.
  if (empty($implementations)) {
    $implementations = cache_get('module_implements');
    if ($implementations === FALSE) {
      $implementations = array();
    }
    else {
      $implementations = $implementations->data;
    }
  }

  if (!isset($implementations[$hook])) {
    $hook_info = module_hook_info();
    $implementations[$hook] = array();
    $list = module_list(FALSE, FALSE, $sort);
    foreach ($list as $module) {
      $include_file = FALSE;
      if (module_hook($module, $hook) || (isset($hook_info[$hook]['group']) && $include_file = module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']) && module_hook($module, $hook))) {
        $implementations[$hook][$module] = $include_file ? $hook_info[$hook]['group'] : FALSE;
        // We added something to the cache, so write it when we are done.
        $implementations['#write_cache'] = TRUE;
      }
    }
  }
  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 module_hook() on
      // each request to avoid undefined function errors.
      if (!module_hook($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]);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.