Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.415.2.22
diff -u -p -r1.415.2.22 theme.inc
--- includes/theme.inc	13 May 2009 19:11:04 -0000	1.415.2.22
+++ includes/theme.inc	18 May 2009 01:47:41 -0000
@@ -278,12 +278,15 @@ function _theme_process_registry(&$cache
       // functions on behalf of core .include files.
       // All files are included to be safe. Conditionally included
       // files can prevent them from getting registered.
-      if (isset($info['file']) && !isset($info['path'])) {
-        $result[$hook]['file'] = $path .'/'. $info['file'];
-        include_once($result[$hook]['file']);
-      }
-      elseif (isset($info['file']) && isset($info['path'])) {
-        include_once($info['path'] .'/'. $info['file']);
+      if (isset($info['file'])) {
+        if (isset($info['path'])) {
+          $file = $info['path'] .'/'. $info['file'];
+        }
+        else {
+          $file = $path .'/'. $info['file'];
+        }
+        include_once($file);
+        $result[$hook]['files'][] = $file;
       }
 
       if (isset($info['template']) && !isset($info['path'])) {
@@ -604,13 +607,11 @@ function theme() {
   // point path_to_theme() to the currently used theme path:
   $theme_path = $hooks[$hook]['theme path'];
 
-  // Include a file if the theme function or preprocess function is held elsewhere.
-  if (!empty($info['file'])) {
-    $include_file = $info['file'];
-    if (isset($info['path'])) {
-      $include_file = $info['path'] .'/'. $include_file;
+  // Include all required files if the theme function or preprocess function is held elsewhere.
+  if (!empty($info['files'])) {
+    foreach ($info['files'] as $file) {
+      include_once($file);
     }
-    include_once($include_file);
   }
   if (isset($info['function'])) {
     // The theme call is a function.
@@ -750,43 +751,48 @@ function path_to_theme() {
  * @param $prefixes
  *   An array of prefixes to test, in reverse order of importance.
  *
- * @return $templates
+ * @return $functions
  *   The functions found, suitable for returning from hook_theme;
  */
 function drupal_find_theme_functions($cache, $prefixes) {
-  $templates = array();
-  $functions = get_defined_functions();
+  $functions = array();
+  $defined_functions = get_defined_functions();
 
   foreach ($cache as $hook => $info) {
     foreach ($prefixes as $prefix) {
       if (!empty($info['pattern'])) {
-        $matches = preg_grep('/^'. $prefix .'_'. $info['pattern'] .'/', $functions['user']);
+        $matches = preg_grep('/^'. $prefix .'_'. $info['pattern'] .'/', $defined_functions['user']);
         if ($matches) {
           foreach ($matches as $match) {
             $new_hook = str_replace($prefix .'_', '', $match);
-            $templates[$new_hook] = array(
+            $functions[$new_hook] = array(
               'function' => $match,
-              'arguments' => $info['arguments'],
               'original hook' => $hook,
             );
+            // Copy specific registry elements from the originating hook.
+            foreach (array('files', 'arguments') as $copy) {
+              if (isset($cache[$hook][$copy])) {
+                $functions[$new_hook][$copy] = $cache[$hook][$copy];
+              }
+            }
           }
         }
       }
       if (function_exists($prefix .'_'. $hook)) {
-        $templates[$hook] = array(
+        $functions[$hook] = array(
           'function' => $prefix .'_'. $hook,
         );
-        // Ensure that the pattern is maintained from base themes to its sub-themes.
-        // Each sub-theme will have their functions scanned so the pattern must be
-        // held for subsequent runs.
-        if (isset($info['pattern'])) {
-          $templates[$hook]['pattern'] = $info['pattern'];
+        // Ensure specific registry elements are passed along and maintained.
+        foreach (array('files', 'pattern') as $copy) {
+          if (isset($cache[$hook][$copy])) {
+            $functions[$new_hook][$copy] = $cache[$hook][$copy];
+          }
         }
       }
     }
   }
 
-  return $templates;
+  return $functions;
 }
 
 /**
@@ -847,11 +853,11 @@ function drupal_find_theme_templates($ca
         'path' => dirname($file->filename),
       );
     }
-    // Ensure that the pattern is maintained from base themes to its sub-themes.
-    // Each sub-theme will have their templates scanned so the pattern must be
-    // held for subsequent runs.
-    if (isset($cache[$hook]['pattern'])) {
-      $templates[$hook]['pattern'] = $cache[$hook]['pattern'];
+    // Ensure specific registry elements are passed along and maintained.
+    foreach (array('files', 'pattern') as $copy) {
+      if (isset($cache[$hook][$copy])) {
+        $templates[$hook][$copy] = $cache[$hook][$copy];
+      }
     }
   }
 
@@ -868,12 +874,18 @@ function drupal_find_theme_templates($ca
         foreach ($matches as $match) {
           $file = substr($match, 0, strpos($match, '.'));
           // Put the underscores back in for the hook name and register this pattern.
-          $templates[strtr($file, '-', '_')] = array(
+          $hook_pattern = strtr($file, '-', '_');
+          $templates[$hook_pattern] = array(
             'template' => $file,
             'path' => dirname($files[$match]->filename),
-            'arguments' => $info['arguments'],
             'original hook' => $hook,
           );
+          // Copy specific registry elements from the originating hook.
+          foreach (array('files', 'arguments') as $copy) {
+            if (isset($cache[$hook][$copy])) {
+              $templates[$hook_pattern][$copy] = $cache[$hook][$copy];
+            }
+          }
         }
       }
     }
