You are here

function content_taxonomy_field in Content Taxonomy 5

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

Implementation of hook_field().

File

./content_taxonomy.module, line 99
Defines a field type for referencing a taxonomy term.

Code

function content_taxonomy_field($op, &$node, $field, &$node_field, $teaser, $page) {
  switch ($op) {
    case 'load':
      if (isset($field['save']) && $field['save'] != 'tag') {
        $data = $node_field;
        unset($node_field);
        foreach ($data as $delta => $value) {
          $term = taxonomy_get_term($value['value']);
          $additions[$field['field_name']][$field['tid']][$term->tid] = $term;
        }
      }
      else {
        $additions[$field['field_name']][$field['tid']] = content_taxonomy_terms_by_field($node, $field['vid'], $field['tid'], $field['depth']);
      }
      $widget_type = $field['widget']['type'];
      $function = $widget_type . "_field_load";
      if (function_exists($function)) {
        $function($op, $node, $field, $node_field, $additions, $teaser, $page);
      }
      return $additions;
      break;
    case 'submit':
      global $content_taxonomy_array_cleared;
      if (!is_array($content_taxonomy_array_cleared) || !$content_taxonomy_array_cleared[$node->nid]) {
        unset($node->taxonomy);
        $content_taxonomy_array_cleared[$node->nid] = true;
      }
      if (isset($field['save']) && $field['save'] != 'cck_table') {
        if (is_array($node_field['tids'])) {
          foreach ($node_field['tids'] as $tid) {
            if ($tid) {
              $node->taxonomy[$field['vid']][$tid] = $tid;
            }
          }
        }
        elseif (is_array($node_field) && $field['save'] == 'both') {
          foreach ($node_field as $tid => $value) {
            if ($tid) {
              $node->taxonomy[$field['vid']][$tid] = $tid;
            }
          }
        }
      }
      break;
    case 'delete':
      taxonomy_node_delete($node->nid);
      break;
  }
}