You are here

function _nat_update_terms in Node Auto Term [NAT] 6.2

Same name and namespace in other branches
  1. 5 nat.module \_nat_update_terms()
  2. 6 nat.module \_nat_update_terms()
  3. 7.2 nat.module \_nat_update_terms()
  4. 7 nat.module \_nat_update_terms()

Update saved node-terms.

Parameters

Object $node: The node object to associate and update.

1 call to _nat_update_terms()
nat_nodeapi in ./nat.module
Implementation of hook_nodeapi().

File

./nat.module, line 530
NAT - node auto term - is a helper module that automatically creates a term using the same title as a node.

Code

function _nat_update_terms($node) {
  $nat_config = _nat_variable_get();
  $edit = array(
    'name' => $node->title,
  );
  $hierarchy = isset($node->taxonomy) ? $node->taxonomy : array();
  $terms = nat_get_terms($node->nid);
  foreach ($terms as $term) {
    $edit['tid'] = $term->tid;
    $edit['vid'] = $term->vid;
    $edit['description'] = isset($nat_config['body'][$node->type]) ? $node->body : $term->description;
    $edit['weight'] = $term->weight;
    $edit['parent'] = isset($hierarchy[$term->vid]) ? $hierarchy[$term->vid] : array();

    // If $node->nat is set, then so is $nat_config['related'][$node->type].
    if (isset($node->nat)) {
      $edit['relations'] = isset($node->nat['related'][$term->vid]) ? $node->nat['related'][$term->vid] : array();
      $edit['synonyms'] = $node->nat['synonyms'];
    }
    taxonomy_save_term($edit);
  }
}