function nat_nodeapi in Node Auto Term [NAT] 6
Same name and namespace in other branches
- 5 nat.module \nat_nodeapi()
- 6.2 nat.module \nat_nodeapi()
Implementation of hook_nodeapi().
File
- ./nat.module, line 76 
- 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':
      // Add term(s).
      $terms = _nat_add_terms($node);
      // Save node-term association in the NAT table.
      _nat_save_association($node->nid, $terms);
      break;
    case 'update':
      // Ensure that this is a node form submission and not a direct node_save
      // operation. @see http://drupal.org/node/197532 and
      // http://drupal.org/node/188377 .
      if (isset($node->form_id)) {
        _nat_update_terms($node);
      }
      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;
  }
}