Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.611
diff -u -p -r1.611 theme.inc
--- includes/theme.inc	14 Sep 2010 21:42:05 -0000	1.611
+++ includes/theme.inc	15 Sep 2010 18:19:12 -0000
@@ -1364,6 +1364,27 @@ function theme_link($variables) {
   return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>';
 }
 
+function template_preprocess_links(&$variables) {
+  if (!empty($variables['links'])) {
+    // Need to rebuild links to retain their defined order.
+    $new = array();
+    foreach ($variables['links'] as $superkey => $links) {
+      // The regular structure of a link item in 'links' does not use element
+      // properties. So if it does, then we're dealing with a super-links-array
+      // and need to flatten.
+      if (element_properties($links)) {
+        foreach (element_children($links) as $key => $link) {
+          $new[$key] = $link;
+        }
+      }
+      elseif (element_child($superkey)) { // @todo Perhaps not required.
+        $new[$superkey] = $link;
+      }
+    }
+    $variables['links'] = $new;
+  }
+}
+
 /**
  * Returns HTML for a set of links.
  *
