diff --git a/nat.module b/nat.module
index c94ce1f..65ee7d2 100755
--- a/nat.module
+++ b/nat.module
@@ -91,7 +91,11 @@ function nat_nodeapi(&$node, $op, $teaser, $page) {
$body = isset($nat_config['body'][$node->type]) ? $body : '';
// Add node title as terms.
- $terms = _nat_add_terms($nat_config['types'][$node->type], $node->title, $body, $node->taxonomy);
+ $term_str = $node->title;
+ if (module_exists('token') && !empty($nat_config['pattern'][$node->type])) {
+ $term_str = token_replace($nat_config['pattern'][$node->type], 'node', $node);
+ }
+ $terms = _nat_add_terms($nat_config['types'][$node->type], $term_str, $body, $node->taxonomy);
// Save node-term association in the NAT table.
_nat_save_association($node->nid, $terms);
@@ -103,7 +107,11 @@ function nat_nodeapi(&$node, $op, $teaser, $page) {
// Update node title in term(s).
$terms = nat_get_terms($node->nid);
- _nat_update_terms($terms, $node->title, $body, $node->taxonomy);
+ $term_str = $node->title;
+ if (module_exists('token') && !empty($nat_config['pattern'][$node->type])) {
+ $term_str = token_replace($nat_config['pattern'][$node->type], 'node', $node);
+ }
+ _nat_update_terms($terms, $term_str, $body, $node->taxonomy);
break;
case 'delete':
// Deleting the associated term when a node is deleted is optional.
@@ -130,6 +138,20 @@ function nat_settings_form() {
$nat_config = variable_get('nat_config', array());
+ if (module_exists('token')) {
+ $form['nat_token_help'] = array(
+ '#title' => t('Help: token replacement patterns'),
+ '#type' => 'fieldset',
+ '#collapsible' => true,
+ '#collapsed' => true,
+ '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
+ '#suffix' => '
',
+ );
+ $form['nat_token_help']['help'] = array(
+ '#value' => theme('token_help', 'node'),
+ );
+ }
+
foreach ($types as $type => $type_object) {
$collapsed = (!isset($nat_config['types'][$type])) || (empty($nat_config['types'][$type]));
$form['nat_'. $type] = array(
@@ -165,6 +187,16 @@ function nat_settings_form() {
'#default_value' => isset($nat_config['node_links'][$type]) ? $nat_config['node_links'][$type] : 0,
'#parents' => array('node_links', $type)
);
+ if (module_exists('token')) {
+ $bt = $nat_config['body'][$type];
+ $form['nat_'. $type]['pattern_'. $type] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pattern'),
+ '#default_value' => (isset($bt) && !is_numeric($bt)) ? $bt : '',
+ '#description' => t('Token-pattern to create taxonomy term. Leave empty to use the node-title.'),
+ '#parents' => array('pattern', $type),
+ );
+ }
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
@@ -180,6 +212,9 @@ function nat_settings_form_submit($form_id, $form_values) {
$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']);
+ if (module_exists('token') && isset($form_values['pattern'])) {
+ $form_values['pattern'] = array_filter($form_values['pattern']);
+ }
variable_set('nat_config', $form_values);
@@ -558,6 +593,11 @@ function _nat_sync_associations($associations) {
$body = isset($nat_config['body'][$node['type']]) ? $node['body'] : '';
// Add node title as terms.
+ $term_str = $node['title'];
+ if (module_exists('token') && !empty($nat_config['pattern'][$node['type']])) {
+ $n = node_load($node['nid']);
+ $term_str = token_replace($nat_config['pattern'][$node['type']], 'node', $n);
+ }
$terms = _nat_add_terms(array($association[1]), $node['title'], $body);
// Save node-term association in the NAT table.