There is slight issue that generates a php notice. If a taxonomy term has been deleted, there is still a reference to its tid in the fields of a node, This means that when the term is loaded, it returns false resulting in notices when the loaded term is expected to be a term object.

Here's a simple patch that checks the term is an object before treating it as one.

Comments

jamiecuthill’s picture

The alternative here is to call array_filter() on the array in the foreach. I would like to see a fix for this committed.

bleen’s picture

StatusFileSize
new1.46 KB

I'd rather cut this off at the source and not put deleted tax terms in that array in the first place. This patch should do it, but I havent had much time to actually test it ... can one of you give this a try.

jamiecuthill’s picture

Your patch is logical but you need to actually assign the $term on line 232.

diff --git a/modules/dart_taxonomy/dart_taxonomy.module b/modules/dart_taxonomy/dart_taxonomy.module
index a3a7e80..f54b192 100644
--- a/modules/dart_taxonomy/dart_taxonomy.module
+++ b/modules/dart_taxonomy/dart_taxonomy.module
@@ -216,6 +216,7 @@ function dart_taxonomy_dart_key_vals($tag) {
       $node_fields = field_info_instances('node', $node->type);
 
       // Iterate over the node fields to find any term reference fields.
+      // @todo There must be a better way to get terms for an entity.
       foreach ($node_fields as $field_name => $field_instance) {
         $field_info = field_info_field($field_name);
         $field_items = field_get_items('node', $node, $field_name);
@@ -224,7 +225,12 @@ function dart_taxonomy_dart_key_vals($tag) {
         if ($field_info['type'] === 'taxonomy_term_reference' && !empty($field_items) && is_array($field_items)) {
           foreach ($field_items as $item) {
             if (!isset($terms[$item['tid']])) {
-              $terms[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
+              // It's possible that a term has been deleted but the tid is still referenced by a node
+              // so we have to check for that.
+              $term = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
+              if (is_object($term)) {
+                $terms[$term->tid] = $term;
+              }
             }
           }
         }
bleen’s picture

StatusFileSize
new1.5 KB

blarrg ... of course. This should do it (and simplify some code a bit). Note that taxonomy_term_load is ultimately cached statically so this change should not affect performance.

bleen’s picture

Status: Needs review » Fixed

committed this to 7.x-2.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.