You are here

function content_taxonomy_field_formatter in Content Taxonomy 5

Implemenation of hook_field_formatter

File

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

Code

function content_taxonomy_field_formatter($field, $item, $formatter, $node) {
  $terms = array();
  if ($node->in_preview) {
    if (is_array($item)) {
      foreach ($item as $key => $tid) {
        $item[$key] = taxonomy_get_term($tid);
      }
    }
  }
  if (!is_array($item)) {
    return '';
  }
  if ($formatter == 'link') {
    foreach ($item as $key => $term) {
      if (!is_object($term) && $key == 'value' && is_numeric($term) && $term != 0) {
        $term = taxonomy_get_term($term);
      }
      if (!empty($term->name)) {
        $terms[] = l($term->name, taxonomy_term_path($term), array(
          'rel' => 'tag',
          'title' => $term->description,
        ));
      }
    }
  }
  else {
    foreach ($item as $key => $term) {
      if (!is_object($term) && $key == 'value' && is_numeric($term) && $term != 0) {
        $term = taxonomy_get_term($term);
      }
      if (!empty($term->name)) {
        $terms[] = check_plain($term->name);
      }
    }
  }
  return implode('<br />', $terms);
}