Here is the code I added to the nat.module to change taxonomy links that are related to a node to link to that node.

function nat_link_alter(&$node, &$links) {

  foreach ($links AS $module => $link) {
      if (strstr($module, 'taxonomy_term')) {
        $tids = array();
        $tids[] = str_replace('taxonomy/term/', '', $link['href']);
        $nids = nat_get_nids($tids);
        if($nids[0]) {
          // Link back to the NAT node and not the taxonomy term page
          $links[$module]['href'] = drupal_get_path_alias("node/{$nids[0]}");
        }
      }
    }
} 
CommentFileSizeAuthor
#4 nat_link_alter.2.patch1.71 KBgryste
#3 nat_link_alter.patch1.34 KBgryste

Comments

gryste’s picture

I've tested this and it works perfectly. Thanks, this is an excellent addition!

Zen’s picture

Status: Active » Needs work

Could you guys convert this into a patch against the -dev version? It would also be useful if this was a configurable option.

Thanks!
-K

gryste’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 KB

Here's a patch against 1.14.2.7. Tested it on a 5.1 install.

The link change is optional and can be configured for each node type separately.

Note: nat_get_nids has changed in the latest version of nat.module so jpsalter's code above won't work. The line that calls nat_get_nids needs to change:

  $nids = array_keys(nat_get_nids($tids,false));
gryste’s picture

StatusFileSize
new1.71 KB

New patch (with -u) for the same code change.

Zen’s picture

Status: Needs review » Fixed

Nice patch. Committed to D5 and HEAD along with the following changes:

  • strpos is faster than strstr.
  • The drupal_get_path_alias is redundant. Links get url()-ed further down the line anyway.
  • Added some more information to the settings screen string. I was initially confused as to which page this would affect: the originating node type, or the target (vocabulary associated) node type.
  • Fixed a few code style issues.

Thanks gryste.

-K

yched’s picture

Nice feature, but wouldn't it be best to handle this through $vocabulary->module and hook_term_path ?

Zen’s picture

But that would restrict the feature to non-taxonomy module vocabularies only, not to mention that they would have to always belong only to the NAT module. Currently, there are no such restrictions.

Thanks.
-K

JacobSingh’s picture

Status: Fixed » Postponed (maintainer needs more info)

This is not working for me, and I'm not sure why it is built the way it is. In my case, I am doing a site about animals, so I have a cck type called "species" which has nat applied to it. So that when someone makes a blog post about a species, they can tag it. And I want the link that gets displayed with the blog post to reference the species page (node) not the taxonomy.

This code checks for nat_config on $node->type so there is no nat_config for the node->type blog, so nothing happens. It seems that something else is needed here. I'll try to change it, but I wanted to make sure I wasn't missing something.

JacobSingh’s picture

Status: Postponed (maintainer needs more info) » Fixed

Sorry, I missed the additions to the config screen. I get it now :) *grins sheepishly*

Thanks,
J

smitty’s picture

Status: Fixed » Needs review

I tested these changes with the Head Version (Date: 2007-Jun-19) on a 5.1 installation. Here is what I found:

1. When I click on "Preview" after creating an new node I get:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT n.nid, t.name FROM nat n INNER JOIN term_data t USING (tid) WHERE n.tid IN () in C:\Programme\apache2triad\htdocs\drupal\includes\database.mysql.inc on line 172.

2. When I click on "Submit", there is no error or warning. In the vocabulary is created a new term. But there is no node-term-association created, although I checked the checkbox "Associate node body with term description" in the Nat-Configuration.

3. Deleting the node does not delete the term in the vocabulary, although the checkbox "Delete associated term if a node is deleted." is checked.

Any ideas?

Zen’s picture

Status: Needs review » Fixed

I fixed the preview bug today. Please test and let me know.

I cannot reproduce the deletion issue you have mentioned. Please retest and open a separate issue for that. Thanks.

smitty’s picture

Thanks to Zen for the bug fixing. The message associated with the preview is gone now.

Concerning the two other points of my former posting I found now, that the node-term-association is really created and also deleted properly.
But the relation is stored in the nat-table (what I did not see writing my former posting) and not in the term_note-table (as I assumed).

So my problem is, that this relation / the term does not show up anywhere (because the standard taxonomy mechanism look to the term_note-table?). Even if I go to the list of taxonomy-terms and click on the created term I get "There are currently no posts in this category.". So for the user of the site it seems that the relation is not stored.

Am I doing something wrong? Or other way around: Why don't you store the relation in the term_note-table?

Anonymous’s picture

Status: Fixed » Closed (fixed)
jhofer’s picture

Is there a similar fix for the 6.x-1.1-beta? or will the 5.x fix above work just the same?