? .DS_Store
? hook_menu_alter_00.patch
Index: vocabindex.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.module,v
retrieving revision 1.1.2.5.2.83
diff -u -p -r1.1.2.5.2.83 vocabindex.module
--- vocabindex.module	14 Jun 2009 19:54:16 -0000	1.1.2.5.2.83
+++ vocabindex.module	17 Jun 2009 17:23:42 -0000
@@ -50,10 +50,7 @@ define('VOCABINDEX_VI_PAGE', 2);
  * Implementation of hook_perm().
  */
 function vocabindex_perm() {
-  return array(
-    'administer vocabulary index',
-    'view vocabulary index pages',
-  );
+  return array('administer vocabulary index');
 }
 
 /**
@@ -116,12 +113,16 @@ function vocabindex_menu() {
   // VI pages.
   $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE);
   foreach ($vis as $vi) {
-    $item = vocabindex_menu_base() + array(
+    $item = array(
       'title' => $vi->name,
       'description' => check_plain($vi->description),
+      'page callback' => 'vocabindex_view_page',
       // We need to cast out the constant to a string, because the integer will
       // otherwise be replaced with the corresponding part of the menu path.
-      'page arguments' => array($vi->vid, (string) VOCABINDEX_VOC),
+      'page arguments' => array($vi->vid, (string) VOCABINDEX_VOC),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK,
+      'file' => 'vocabindex.view.inc',
     );
     // The menu item for alphabetical VIs using the letter wildcard.
     if ($vi->view == VOCABINDEX_VIEW_ALPHABETICAL) {
@@ -137,29 +138,26 @@ function vocabindex_menu() {
 
 /**
  * Implementation of hook_menu_alter().
- *
- * Overrides taxonomy.module's default /taxonomy/term/tid callback for term
- * index pages.
  */
 function vocabindex_menu_alter(&$items) {
   $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE);
   foreach ($vis as $vi) {
     if ($vi->view == VOCABINDEX_VIEW_FLAT) {
-      $tree = taxonomy_get_tree($vi->vid);
-      $children = vocabindex_get_children($tree);
-      foreach ($tree as $term) {
-        // Check if the current term is a parent.
-        if (isset($children[$term->tid])) {
-          $items['taxonomy/term/' . $term->tid] = vocabindex_menu_base() + array(
-            'title' => $term->name,
-            'description' => check_plain($term->description),
-            // We need to cast our integer constant to a string, because the
-            // integer will otherwise be replaced with the corresponding part
-            // of the menu path.
-            'page arguments' => array($term->tid, (string) VOCABINDEX_TERM),
-            'file path' => drupal_get_path('module', 'vocabindex'),          );
-        }
-      }
+      $item = &$items['taxonomy/term/%'];
+
+      // Store the original configuration, so we can pass it on to our own
+      // callback.
+      $callback = $item['page callback'];
+      $arguments = $item['page arguments'];
+      $file = $item['file'];
+      $filepath = isset($item['file path']) ? $item['file path'] : drupal_get_path('module', $item['module']);
+
+      // Alter the original callback.
+      $item['page callback'] = 'vocabindex_term_page';
+      $item['page arguments'] = array_merge(array(2, $callback, $file, $filepath), $arguments);
+      $item['file'] = 'vocabindex.module';
+      $item['file path'] = drupal_get_path('module', 'vocabindex');
+      break;
     }
   }
 }
@@ -364,18 +362,6 @@ function _vocabindex_menu_paths($section
 }
 
 /**
- * Returns the basics for a VI menu item.
- */
-function vocabindex_menu_base() {
-  return array(
-    'access arguments' => array('view vocabulary index pages'),
-    'page callback' => 'vocabindex_view_page',
-    'type' => MENU_CALLBACK,
-    'file' => 'vocabindex.view.inc',
-  );
-}
-
-/**
  * Check if the latest DB updates for this module have been performed.
  */
 function vocabindex_update_status() {
@@ -395,6 +381,38 @@ function vocabindex_update_status() {
 }
 
 /**
+ * Route a term page request to the right callback function.
+ *
+ * @param $tid
+ *   The TID of the term to call a callback for.
+ * @param $callback
+ *   The name of the original callback function.
+ * @param $file
+ *   The file the original term callback is in.
+ * @param $filepath
+ *   The path to $file.
+ * @param ...
+ *   Additional arguments to pass along to the theme function.
+ *
+ * @return
+ *   An HTML string that generates the themed output.
+ */
+function vocabindex_term_page($tid, $callback, $file, $filepath) {
+  $term = taxonomy_get_term($tid);
+  $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE);
+  foreach ($vis as $vi) {
+    if ($vi->vid == $term->vid) {
+      module_load_include('inc', 'vocabindex', 'vocabindex.view');
+      return vocabindex_view_page($tid, VOCABINDEX_TERM);
+    }
+  }
+
+  require_once($filepath .'/'. $file);
+  $arguments = array_slice(func_get_args(), 4);
+  return call_user_func_array($callback, $arguments);
+}
+
+/**
  * Menu path wildcard for alphabetical VIs.
  *
  * @param $letter
