Duplicate key error and missing token if a taxonomy term is set both in $node->taxonomy and $node->primaryterm

tuffnatty - October 14, 2009 - 09:09
Project:Primary Term
Version:6.x-1.0
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

Here is a patch fixing that behaviour:

-- primary_term.module.orig    2008-09-15 18:14:57.000000000 +0400
+++ primary_term.module 2009-10-12 14:17:26.000000000 +0400
@@ -34,16 +34,16 @@
         $tid = $node->primary_term->tid;
       }
       if (!empty($tid)) {
+        // Load the term so it's available to token/pathauto
+        $node->primary_term = taxonomy_get_term($tid);
         foreach ($node->taxonomy as $k => $v) {
-          if (is_array($v) && !empty($v[$tid])) {
+          if (is_array($v) && in_array($tid, $v)) {
             return;
           } else if (is_numeric($v) && $v == $tid) {
             return;
           }
         }
-        $node->taxonomy[] = $tid;
-        // Load the term so it's available to token/pathauto
-        $node->primary_term = taxonomy_get_term($tid);
+        $node->taxonomy[$node->primary_term->vid][] = $tid;
       }
       break;
    

 
 

Drupal is a registered trademark of Dries Buytaert.