=== modified file 'sites/all/modules/nat/nat.admin.inc' --- nat.admin.inc 2010-07-15 11:50:29 +0000 +++ nat.admin.inc 2010-11-26 21:11:11 +0000 @@ -49,6 +49,13 @@ function nat_settings_form() { '#default_value' => isset($nat_config['delete'][$type]) ? $nat_config['delete'][$type] : 0, '#parents' => array('delete', $type) ); + $form['nat_'. $type]['reuse_terms_'. $type] = array( + '#type' => 'checkbox', + '#title' => t('Reuse existing terms.'), + '#default_value' => isset($nat_config['reuse_terms'][$type]) ? $nat_config['reuse_terms'][$type] : 0, + '#description' => t('By default, new terms will always be created in the selected vocabularies, upon creating a new node (and during Sync). Checking this option will instead create an association to an existing term with the same name, if possible. (If multiple terms with the same name exist in a vocabulary, an association is made to one of the terms. Matching is case insensitive.)'), + '#parents' => array('reuse_terms', $type) + ); $form['nat_'. $type]['related_'. $type] = array( '#type' => 'checkbox', '#title' => t('Allow users to define synonyms and related terms when they create and edit nodes.'), @@ -77,6 +84,7 @@ function nat_settings_form_submit($form, $form_values['body'] = array_filter($form_values['body']); $form_values['delete'] = array_filter($form_values['delete']); + $form_values['reuse_terms'] = array_filter($form_values['reuse_terms']); $form_values['node_links'] = array_filter($form_values['node_links']); $form_values['related'] = array_filter($form_values['related']); === modified file 'sites/all/modules/nat/nat.module' --- nat.module 2010-11-26 14:36:26 +0000 +++ nat.module 2010-11-26 21:11:39 +0000 @@ -488,11 +488,14 @@ function _nat_get_vocabularies() { */ function _nat_add_terms($node, $vids = array()) { $nat_config = _nat_variable_get(); + $existing_terms = array(); + if (isset($nat_config['reuse_terms'][$node->type])) { + $existing_terms = taxonomy_get_term_by_name($node->title); + } $edit = array( 'name' => $node->title, 'description' => isset($nat_config['body'][$node->type]) ? $node->body : '', - 'weight' => 0 ); $tids = array(); @@ -505,6 +508,15 @@ function _nat_add_terms($node, $vids = a unset($edit['tid']); $edit['vid'] = $vid; + $edit['weight'] = 0; + foreach ($existing_terms as $eterm) { + if ($eterm->vid == $vid) { + // Update the existing term, just as in _nat_update_terms() + $edit['tid'] = $eterm->tid; + $edit['weight'] = $eterm->weight; + } + } + // Save hierarchy for vocabularies also present in the node form. if (isset($hierarchy[$vid])) { $edit['parent'] = $hierarchy[$vid]; @@ -606,6 +618,7 @@ function _nat_variable_get($name = NULL) 'types' => array(), 'body' => array(), 'delete' => array(), + 'reuse_terms' => array(), 'related' => array(), 'node_links' => array() );