You are here

function nat_nodeapi in Node Auto Term [NAT] 5

Same name and namespace in other branches
  1. 6.2 nat.module \nat_nodeapi()
  2. 6 nat.module \nat_nodeapi()

Implementation of hook_nodeapi().

File

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

Code

function nat_nodeapi(&$node, $op, $teaser, $page) {
  $nat_config = _nat_variable_get();
  if (!isset($nat_config['types'][$node->type]) || empty($nat_config['types'][$node->type])) {
    return;
  }
  switch ($op) {
    case 'load':
      $node->nat = nat_get_terms($node->nid);
      break;
    case 'insert':
      $body = $node->body;

      // Copying over the node body is optional.
      $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, $node->nat['related'], $node->nat['synonyms']);

      // Save node-term association in the NAT table.
      _nat_save_association($node->nid, $terms);
      break;
    case 'update':
      $body = $node->body;

      // Copying over the node body is optional.
      $body = isset($nat_config['body'][$node->type]) ? $body : '';

      // Update node title in term(s).
      $terms = nat_get_terms($node->nid);
      _nat_update_terms($terms, $node->title, $body, $node->taxonomy, $node->nat['related'], $node->nat['synonyms']);
      break;
    case 'delete':

      // Deleting the associated term when a node is deleted is optional.
      if (isset($nat_config['delete'][$node->type])) {
        _nat_delete_terms($node->nid);
      }

      // Delete node-term association from the NAT table.
      _nat_delete_association($node->nid);
      break;
  }
}