Node navigation theme does not allow for more than one edition

Anselm Heaton - July 31, 2008 - 10:08
Project:E-Publish
Version:6.x-1.0-beta2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Epublish allows users to add the same node in several different editions. This is good (in a scenario with several publications, you may want the same article in several of the publications).

However the theming function epublish_navigation is only given one of the editions (the first one returned by the db, unordered). The following patch fixes this, by providing an array of editions to the epublish_navigation function. Themers can still decided to show only one of the editions.

Index: epublish.module
===================================================================
--- epublish.module
+++ epublish.module
@@ -523,9 +523,13 @@
                case 'view':
                        // append epublish navigation to all nodes that belong to an edition
                        if (!$a3) {
-                               $eid = db_result(db_query('SELECT eid FROM {epublish_edition_node} een WHERE nid = %d', $node->nid));
-                       if ($eid) {
-                               $node = theme('epublish_navigation', $node, $eid);
+              $result = db_query('SELECT eid FROM {epublish_edition_node} een WHERE nid = %d', $node->nid);
+              $editions = array();
+              while ($ed = db_fetch_object($result)) {
+                $editions[] = $ed->eid;
+              }
+                       if (count($editions)) {
+                               $node = theme('epublish_navigation', $node, $editions);
                        }
                        }
                        break;
@@ -3161,19 +3165,26 @@
  * @ingroup themeable
  */

-function theme_epublish_navigation($node, $eid) {
-  if ($node->nid) {
+function theme_epublish_navigation($node, $editions) {
+  if (!$node->nid || count($editions) == 0) {
+    return $node;
+  }
+
+  $node->breadcrumb = array();
+  $output = '';
+  foreach ($editions as $eid) {
     $output .= '<div class="epublish_navigation">';
     $edition = epublish_get_edition($eid);
     $publication = epublish_get_pub($edition->pid);
     $sid = epublish_assign_section($edition);
     $topics = epublish_section_topics($sid, $edition->eid);
-    // Construct the breadcrumb:
-    $node->breadcrumb = array();
-    $node->breadcrumb[] = l(t($publication->name),"epublish/$publication->pid");
-    $node->breadcrumb[] = l(t(theme('epublish_edition_reference', $edition)),"epublish/$edition->pid/$edition->eid");
-    $node->breadcrumb[] = l(t($node->title),"node/$node->nid");
-    drupal_set_breadcrumb($node->breadcrumb);
+    // Construct the breadcrumb to the first edition
+    if (!count($node->breadcrumb)) {
+      $node->breadcrumb[] = l(t($publication->name),"epublish/$publication->pid");
+      $node->breadcrumb[] = l(t(theme('epublish_edition_reference', $edition)),"epublish/$edition->pid/$edition->eid");
+      $node->breadcrumb[] = l(t($node->title),"node/$node->nid");
+      drupal_set_breadcrumb($node->breadcrumb);
+    }
     if ($prev = epublish_prev($node, $topics)) {
       $links[] = t("Previous story: ") . l($prev->title, 'node/'. $prev->nid);
     }
@@ -3184,9 +3195,9 @@
     $output .= theme('item_list', $links);
     $output .= '</div>';
   }
+
   $node->content['body']['#value'] = $node->body.$output;
   return $node;
-
}

function epublish_prev($node, $topics) {

 
 

Drupal is a registered trademark of Dries Buytaert.