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.)
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | nat.module_term_nat-03.patch | 1.97 KB | smokris |
| #4 | nat.module_term_nat-02.patch | 1.55 KB | smokris |
| #3 | nat.module_term_nat-01.patch | 1.45 KB | smokris |
| #1 | nat.module_term_nat.patch | 1.13 KB | nonsie |
Comments
Comment #1
nonsie+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
Comment #2
Zen commentedPlease 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
Comment #3
smokrisI've attempted Zen's suggestion from #2, and modified hook_link_alter() to make use of it.
Comment #4
smokris(oops.. try this patch instead of the above.)
Comment #5
Zen commentedCheers smokris :)
-K
Comment #6
smokrisI've addressed your four issues in #5, and re-rolled this patch against the current 6.x-1.x-dev version.
Comment #7
jbomb commentedThanks 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.
Comment #8
TKS commented+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?
Comment #9
batje commentedHow did this not make it in 6.x-1.2 ?
Comment #10
stefan81 commentedsubscribe