=== modified file 'sites/all/modules/nat/nat.admin.inc' --- sites/all/modules/nat/nat.admin.inc 2010-07-15 11:50:29 +0000 +++ sites/all/modules/nat/nat.admin.inc 2010-07-14 14:44:31 +0000 @@ -58,9 +58,17 @@ $form['nat_'. $type]['node_links_'. $type] = array( '#type' => 'checkbox', '#title' => t('Make NAT terms in %type node views point to the associated node rather than the taxonomy page.', array('%type' => $type)), + '#description' => t('Note that this is option is not usually turned on for the node type which has a vocabulary enabled for NAT (in this settings screen), but for other node types which allow users to select terms from a NAT-enabled vocabulary.'), '#default_value' => isset($nat_config['node_links'][$type]) ? $nat_config['node_links'][$type] : 0, '#parents' => array('node_links', $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['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); @@ -77,8 +85,9 @@ $form_values['body'] = array_filter($form_values['body']); $form_values['delete'] = array_filter($form_values['delete']); + $form_values['related'] = array_filter($form_values['related']); $form_values['node_links'] = array_filter($form_values['node_links']); - $form_values['related'] = array_filter($form_values['related']); + $form_values['reuse_terms'] = array_filter($form_values['reuse_terms']); variable_set('nat_config', $form_values); === modified file 'sites/all/modules/nat/nat.module' --- sites/all/modules/nat/nat.module 2010-07-15 11:50:29 +0000 +++ sites/all/modules/nat/nat.module 2010-07-14 14:44:58 +0000 @@ -480,11 +480,14 @@ */ 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(); @@ -497,13 +500,17 @@ 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]; - } - else { - $edit['parent'] = array(); - } + $edit['parent'] = isset($hierarchy[$vid]) ? $hierarchy[$vid] : array(); $edit['relations'] = isset($node->nat) && isset($node->nat['related'][$vid]) ? $node->nat['related'][$vid] : array(); $edit['synonyms'] = isset($node->nat) ? $node->nat['synonyms'] : ''; @@ -598,7 +605,8 @@ 'body' => array(), 'delete' => array(), 'related' => array(), - 'node_links' => array() + 'node_links' => array(), + 'reuse_terms' => array(), ); $variables = variable_get('nat_config', array()); $variables = array_merge($defaults, $variables);