This is very strange, I have one content type that is not loading $node->taxonomy when being themed. I went into node.tpl.php (no custom templates) and did a print_r($node). For most content types, $node-taxonomy is loaded, but for this one, it is not. What could be preventing that? Just to make it a little stranger, it's fine in 6.4, but not in 5.10.

Oh, I have also tried two different themes (Bluemarine and Garland) with the same result.

Comments

Gemma Morton’s picture

Silly question, are you sure there's a Vocabulary assigned to that content type?

nancydru’s picture

Yes, I double checked. However, the module is taxonomy-based so it wouldn't even function otherwise.

NancyDru (formerly Nancy W. until I got married to Drupal)

Gemma Morton’s picture

Do you have a separate node tpl file for that content type... Such as node-movie.tpl.php? If so, make sure the relevant code is there. If not, try making one, by copying your node.tpl.php file and naming it: node-custom-name-here.tpl.php Custom Name Here being the Machine Readable name of your Content Type.

I am readily assuming here though that you have more than one content type, and the taxonomy displays for the others...?

nancydru’s picture

Yes, it displays for the others. No, I do not have any custom node templates. I created a custom template that was just a copy of the standard one. It still doesn't show the terms.

NancyDru (formerly Nancy W. until I got married to Drupal)

Gemma Morton’s picture

What modules are you using? That would be a start.

Also, under your Content Type Admin Settings, goto: Display Settings and Make sure the Taxonomy displays for the Full Node.

nancydru’s picture

This is not a CCK content; I have never heard of such a setting in anything but CCK. This is the Web Links module.

NancyDru (formerly Nancy W. until I got married to Drupal)

alan d.’s picture

Have you run the sql directly? For D6 & D5, using the revision vid and if that fails, the node nid (thinking corrupt vid):

SELECT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid WHERE r.vid = XXX ORDER BY v.weight, t.weight, t.name

Notice that if the revision doesn't get updated in that module, and it handles it's taxonomic relationships itself, you'll keep lossing the terms.

Theming functions don't load these directly, but a call to taxonomy_node_get_terms($node) may be a work around at the theming layer, if the above SQL works that is!


Alan Davison
www.caignwebs.com.au

Alan Davison
nancydru’s picture

I don't know what the point of this query is, however, it is flawed. Term_node does not have a vid column (WHERE r.vid=xxx). Remember that D5 does not track revisions to terms. It is unlikely that revisions is the problem since it is turned off.

I changed the query to

SELECT r.nid, t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid WHERE t.vid = 15 ORDER BY v.weight, t.weight, t.name

Everything looks right.

The module does not manage the terms itself; we are quite happy to let core do that. When I edit the node, it shows the correct terms, so the relationship is still intact.

Yes, I could fix it on my site, but my users aren't helped. I am a co-maintainer on this contributed module. I cannot provide a theme solution for every possible theme there is.

NancyDru (formerly Nancy W. until I got married to Drupal)

alan d.’s picture

By any chance, do you have any other modules that are setting the $node->taxonomy value. It sounds like either this is being overwritten by another module or maybe by mistake during a conditional check or something.

The taxonomy load could be moved another hook_nodeapi('load',..) or hook_nodeapi('view', ..) as a temporary fix while the real problem is investigated further.

Just had a play with a new idea for a debugging tool, and I came up with the following class. It will only help is the call is deep in core, as it does kill the processing of the node, resulting in a 404/blank screen.

<?php

class node_wrapper {

  private $values = NULL;
  
  public function __construct($values) {
    $this->values = $values;
  }
  
  public function __set($name, $value) {
    if ($name == 'taxonomy') {
      $msg = '<pre>';
      $msg .=  'Setting ' . $name . ' to ' . print_r($value, TRUE);
      foreach(debug_backtrace() as $trace) {
        $msg .=  $trace['node_load'] . ' ' . $trace['line'] . ' '.  $trace['file'] . "\n" ;
      }
      $msg .=  '</pre>';
      drupal_set_message($msg);
    }
    $this->values->{$name} = $value;
  }
  
  public function __get($name) {
    return $this->values->{$name};
  }
}

?>

If you throw in this wrapper in before the line in node.module after the fetch object call, it may help track the problem.

<?php
function node_load($param = array(), $revision = NULL, $reset = NULL) {
  static $nodes = array();

  ......


  if ($revision) {
    array_unshift($arguments, $revision);
    $node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
  }
  else {
    $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
  }

  ############ adds debugging, bout line 590 in node.module ################
  $node = new node_wrapper($node);

  if ($node->nid) {
    // Call the node specific callback (if any) and piggy-back the
    // results to the node or overwrite some values.
    if ($extra = node_invoke($node, 'load')) {
      foreach ($extra as $key => $value) {
        $node->$key = $value;
      }
    }

....
?>

PS: I missed the vid/nid in the query while I was taking a quick look at the functions, sorry about that.


Alan Davison
www.caignwebs.com.au

Alan Davison
nancydru’s picture

I added this to the hook_view, immediately before the return:

  $node->content['dump'] = array(
    '#value' => '<pre>'. print_r($node, true) .'</pre><br />',
    '#weight' => 10,
    );

And the correct taxonomy section is there.

Further, I have a block that shows the terms of the current node and it shows them correctly.

I did check and the site that is messed up does have revisions. I have another 5.10 site that does not and it is properly showing the terms.

NancyDru (formerly Nancy W. until I got married to Drupal)

nancydru’s picture

If I access the nodes through taxonomy/term/406 or node/type/weblinks the terms show up correctly.

nancydru’s picture

Okay, here's what I have found so far: node_build_content is being called twice for each node display. Within it, there is a call to hook_nodeapi('view'). After the first call, the taxonomy section is still present, but after the second call, it is gone.

The taxonomy module does not have "view" processing, so we can eliminate that module. My module also does not do "view," so we can probably leave out shooting myself in the foot.

nancydru’s picture

It's in another one of my modules...

alan d.’s picture

Was it a bug in one of the mainstream modules or a custom one?


Alan Davison
www.caignwebs.com.au

Alan Davison
nancydru’s picture

Taxonomy_image_node_display. It is fixed now.