I needed a way to easily construct URL references to the NAT node, given only the corresponding term's TID, so I patched `nat.module` as follows:

Index: nat.module
===================================================================
--- nat.module	(revision 5014)
+++ nat.module	(working copy)
@@ -57,10 +57,25 @@
     'access arguments' => array('administer NAT configuration'),
     'type' => MENU_LOCAL_TASK
   );
+  $items['taxonomy/term/%/nat'] = array(
+    'title' => 'NAT for term',
+    'page callback' => 'nat_tid_to_node',
+    'page arguments' => array(2),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
 
+function nat_tid_to_node($tid)
+{
+  $nids = array_keys(nat_get_nids(array($tid), FALSE));
+  if (!empty($nids)) {
+    drupal_goto("node/$nids[0]");
+  }
+}
+
 /**
  * Implementation of hook_views_api().
  *

(After adding this code you need to "Clear cached data" on `/admin/settings/performance` for it to work.)

Comments

nonsie’s picture

StatusFileSize
new1.13 KB

+2 for this one. I've added one minor addition - if the term is not nat term redirect to term page.
Patch against 6.x-1.1-beta2 attached

Zen’s picture

Status: Needs review » Needs work

Please spin off the URL block into a helper function - it can also be reused in hook_link_alter and possibly by other modules. Return FALSE if not a NAT node.

Cheers,
-K

smokris’s picture

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

I've attempted Zen's suggestion from #2, and modified hook_link_alter() to make use of it.

smokris’s picture

StatusFileSize
new1.55 KB

(oops.. try this patch instead of the above.)

Zen’s picture

Status: Needs review » Needs work
  • Shouldn't it be nat_goto_node() and nat_get_path_for_node()?
  • Avoid cuddling the 'else' on the same line.
  • Please add doxygen comments for both functions.
  • Please shove them both down - there should be a section for menu callbacks and another further down for other helper functions.

Cheers smokris :)

-K

smokris’s picture

Version: 6.x-1.1-beta2 » 6.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.97 KB

I've addressed your four issues in #5, and re-rolled this patch against the current 6.x-1.x-dev version.

jbomb’s picture

Thanks smokris! i'm using the patch from #6 with a hook_menu_alter implementation as Zen described in #2.

All of my terms with NAT relationships always link to the NAT node rather than the taxonomy page. It's exactly what I needed.

TKS’s picture

+1 for this feature.

The content-type-specific nat_link_alter option that's part of the current module is helpful, but I really need to have NAT-related terms always point to the associated node, regardless of where they appear. In a perfect world, this would be another checkbox under each content type at admin/settings/nat.

It seems like the patch from #6 has been through several rounds of revisions. Zen, is this something that's likely headed for the dev version or the beta-4 release? (I don't want to patch locally and then lose the functionality on the next module update.) Or would I be better off dropping this functionality into a custom module for now?

batje’s picture

How did this not make it in 6.x-1.2 ?

stefan81’s picture

subscribe