? nat.attach-term.patch
? nat1.patch
Index: nat.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nat/Attic/nat.admin.inc,v
retrieving revision 1.1.2.2
diff -u -u -r1.1.2.2 nat.admin.inc
--- nat.admin.inc	1 Mar 2009 07:27:51 -0000	1.1.2.2
+++ nat.admin.inc	17 Sep 2009 12:18:05 -0000
@@ -56,6 +56,12 @@
       '#default_value' => isset($nat_config['node_links'][$type]) ? $nat_config['node_links'][$type] : 0,
       '#parents' => array('node_links', $type)
     );
+    $form['nat_'. $type]['attach_'. $type] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Attach the newly created term to the %type node.', array('%type' => $type)),
+      '#default_value' => isset($nat_config['attach'][$type]) ? $nat_config['attach'][$type] : 0,
+      '#parents' => array('attach', $type)
+    );
   }
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
 
@@ -72,8 +78,10 @@
 
   $form_values['body'] = array_filter($form_values['body']);
   $form_values['delete'] = array_filter($form_values['delete']);
-  $form_values['node_links'] = array_filter($form_values['node_links']);
   $form_values['related'] = array_filter($form_values['related']);
+  $form_values['node_links'] = array_filter($form_values['node_links']);
+  $form_values['attach'] = array_filter($form_values['attach']);
+
 
   variable_set('nat_config', $form_values);
 
Index: nat.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nat/nat.install,v
retrieving revision 1.9
diff -u -u -r1.9 nat.install
--- nat.install	14 May 2008 20:54:37 -0000	1.9
+++ nat.install	17 Sep 2009 12:18:05 -0000
@@ -59,7 +59,16 @@
   while ($node = db_fetch_array($result)) {
     db_query('UPDATE {nat} SET vid = %d WHERE nid = %d AND tid = %d', $node['vid'], $node['nid'], $node['tid']);
   }
-  
+
+  return $ret;
+}
+
+/**
+ * Update the module weight to lower than taxonomy (0).
+ */
+function nat_update_3() {
+  $ret = array();
+  db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", -1, 'nat');
   return $ret;
 }
 
Index: nat.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nat/nat.module,v
retrieving revision 1.34.2.18
diff -u -u -r1.34.2.18 nat.module
--- nat.module	1 Mar 2009 07:27:51 -0000	1.34.2.18
+++ nat.module	17 Sep 2009 12:18:06 -0000
@@ -90,6 +90,9 @@
 
       // Save node-term association in the NAT table.
       _nat_save_association($node->nid, $terms);
+      if (isset($nat_config['attach'][$node->type])) {
+        _nat_apply_node_terms($node);
+      }
       break;
     case 'update':
       // Ensure that this is a node form submission and not a direct node_save
@@ -97,6 +100,9 @@
       // http://drupal.org/node/188377 .
       if (isset($node->form_id)) {
         _nat_update_terms($node);
+        if (isset($nat_config['attach'][$node->type])) {
+          _nat_apply_node_terms($node);
+        }
       }
       break;
     case 'delete':
@@ -106,11 +112,24 @@
       }
       // Delete node-term association from the NAT table.
       _nat_delete_association($node->nid);
+      if (isset($nat_config['attach'][$node->type])) {
+        _nat_apply_node_terms($node);
+      }
       break;
   }
 }
 
 /**
+ * Update $node->taxonomy from the terms stored in {nat}.
+ */
+function _nat_apply_node_terms(&$node) {
+  $result = db_query('SELECT vid, tid FROM {nat} WHERE nid = %d', $node->nid);
+  while ($row = db_fetch_object($result)) {
+    $node->taxonomy[$row->vid] = $row->tid;
+  }
+}
+
+/**
  * Implementation of hook_form_alter().
  */
 function nat_form_alter(&$form, &$form_state, $form_id) {
@@ -599,7 +618,8 @@
       'body' => array(),
       'delete' => array(),
       'related' => array(),
-      'node_links' => array()
+      'node_links' => array(),
+      'attach' => array(),
     );
     $variables = variable_get('nat_config', array());
     $variables = array_merge($defaults, $variables);
