Add URLs for referencing NAT nodes by TID
smokris - February 7, 2009 - 06:10
| Project: | Node Auto Term [NAT] |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
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:
<?php
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.)

#1
+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
#2
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
#3
I've attempted Zen's suggestion from #2, and modified hook_link_alter() to make use of it.
#4
(oops.. try this patch instead of the above.)
#5
Cheers smokris :)
-K
#6
I've addressed your four issues in #5, and re-rolled this patch against the current 6.x-1.x-dev version.
#7
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.
#8
+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?