diff --git a/includes/module.inc b/includes/module.inc index 0c06609..3748f60 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -747,18 +747,37 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) { // 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; + // Discover implementations for this hook. - $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; + // Determine if a "group" is specified for this hook. + $hook_info = module_hook_info(); + if (isset($hook_info[$hook]['group'])) { + // If a "group" is specified, implementations may live in lazy-loaded + // files named "$module.$group.inc". + $group = $hook_info[$hook]['group']; + foreach (module_list(FALSE, FALSE, $sort) as $module) { + // Include $module.$group.inc, if it exists. + $group_file_exists = module_load_include('inc', $module, "$module.$group"); + // Determine whether the module implements the hook. + // 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] = $group_file_exists ? $group : FALSE; + } } } + else { + // If no "group" is specified, module_implements() will not include any + // additional files. + foreach (module_list(FALSE, FALSE, $sort) as $module) { + // Determine whether the module implements the hook. + if (function_exists($module . '_' . $hook)) { + $implementations[$hook][$module] = FALSE; + } + } + } + // Allow modules to change the weight of specific implementations, but avoid // an infinite loop. if ($hook != 'module_implements_alter') {