Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.206
diff -u -p -r1.206 module.inc
--- includes/module.inc	21 Nov 2010 10:19:48 -0000	1.206
+++ includes/module.inc	22 Nov 2010 00:25:46 -0000
@@ -695,11 +695,12 @@ function module_implements($hook, $sort 
  * Retrieve a list of what hooks are explicitly declared.
  */
 function module_hook_info() {
-  $hook_info = &drupal_static(__FUNCTION__, array());
+  $hook_info = &drupal_static(__FUNCTION__);
 
-  if (empty($hook_info)) {
+  if (!isset($hook_info)) {
+    $hook_info = array();
     $cache = cache_get('hook_info', 'cache_bootstrap');
-    if ($cache === FALSE) {
+    if (!$cache) {
       // Rebuild the cache and save it.
       // We can't use module_invoke_all() here or it would cause an infinite
       // loop.
@@ -763,10 +764,21 @@ function module_invoke() {
   $module = $args[0];
   $hook = $args[1];
   unset($args[0], $args[1]);
-  if (module_hook($module, $hook)) {
+  $hook_exists = function_exists($module . '_' . $hook);
+  // If the hook implementation does not exist, check whether it may live in an
+  // optional include file registered via hook_hook_info().
+  if (!$hook_exists) {
+    $hook_info = module_hook_info();
+    if (isset($hook_info[$hook]['group'])) {
+      module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
+      $hook_exists = function_exists($module . '_' . $hook);
+    }
+  }
+  if ($hook_exists) {
     return call_user_func_array($module . '_' . $hook, $args);
   }
 }
+
 /**
  * Invoke a hook in all enabled modules that implement it.
  *
@@ -783,6 +795,15 @@ function module_invoke_all() {
   $args = func_get_args();
   $hook = $args[0];
   unset($args[0]);
+
+  // Check whether the hook may live in optional include files registered via
+  // hook_hook_info().
+  $hook_info = module_hook_info();
+//  static $d; if (!isset($d)) $d = 1 && dsm($hook_info);
+  if (isset($hook_info[$hook]['group'])) {
+    module_load_all_includes('inc', $module, $module . '.' . $hook_info[$hook]['group']);
+  }
+
   $return = array();
   foreach (module_implements($hook) as $module) {
     $function = $module . '_' . $hook;
