You are here

function theme_taxonomy_list_term in Taxonomy List 6

Same name and namespace in other branches
  1. 5.2 taxonomy_list.module \theme_taxonomy_list_term()
  2. 5 taxonomy_list.module \theme_taxonomy_list_term()
  3. 6.2 taxonomy_list.module \theme_taxonomy_list_term()
  4. 7 taxonomy_list.module \theme_taxonomy_list_term()

Theme the term.

1 theme call to theme_taxonomy_list_term()
theme_taxonomy_list_get_table in ./taxonomy_list.module
Generate cascaded tables with terms and sub terms inside

File

./taxonomy_list.module, line 439
List all terms in a vocabulary.

Code

function theme_taxonomy_list_term($term, $vocabulary, $controls) {
  $output = '<div class="taxonomy-list-item taxonomy-list-term-' . $term->tid . '">';
  $term_path = taxonomy_term_path($term);
  if ($controls['taxonomy_image'] && $controls['show_image']) {
    $links = array();
    $overrides = array(
      'resize' => 1,
      'width' => 32,
      'height' => 32,
    );
    switch ($controls['image_link']) {
      case 'term':

        // Must use the 'html' flag for the l() function.
        $links['taxonomy-list-image'] = array(
          'title' => $controls['block'] ? taxonomy_image_display($term->tid, array(), 'ORIGINAL', $overrides) : taxonomy_image_display($term->tid, NULL, NULL, array(
            'wrapper' => FALSE,
          )),
          'href' => $term_path,
          'html' => TRUE,
        );
        break;
      case 'big':
        $obj = taxonomy_image_get_object($term->tid);
        $links['taxonomy-list-image'] = array(
          'title' => $controls['block'] ? taxonomy_image_display($term->tid, array(), 'ORIGINAL', $overrides) : taxonomy_image_display($term->tid, NULL, NULL, array(
            'wrapper' => FALSE,
          )),
          'href' => $obj->url,
          'html' => TRUE,
        );
    }
    $output .= theme('links', $links);
  }
  switch ($controls['count_type']) {
    case 'none':
      $counter = NULL;
      break;
    case 'all':
      $count = taxonomy_term_count_nodes($term->tid);
      if ($count == 0 && $controls['no_show']) {
        return NULL;
      }
      $counter = '<div class="taxonomy-list-term-count">(' . $count . ')</div>';
      break;
    case 'not_zero':
    case 'by_type':
      $count_list = array();
      $count = 0;
      foreach ($vocabulary->nodes as $type) {
        $this_count = taxonomy_term_count_nodes($term->tid, $type);
        if ($this_count > 0 || $controls['count_type'] == 'by_type') {

          // Is Node Type Filter available?
          if ($controls['ntf_avail'] && $this_count > 0) {
            $count_list[] = l($type . ': ' . $this_count, $term_path, array(
              'query' => 'type=' . $type,
            ));
          }
          else {
            $count_list[] = $type . ': ' . $this_count;
          }
        }
        $count += $this_count;
      }
      if ($count == 0 && $controls['no_show']) {
        return NULL;
      }
      if ($count_list) {
        $counter = '<div class="taxonomy-list-term-count">(' . implode(', ', $count_list) . ')</div>';
      }
      break;
  }

  // Create the term name as a taxonomy/term link with this term's tid as
  // a named anchor (for related links).
  $output .= '<a name="' . $term->tid . '"></a>' . l(check_plain($term->name), taxonomy_term_path($term) . $controls['kids'], array(
    'attributes' => array(
      'class' => 'taxonomy-list-term',
    ),
    'html' => TRUE,
  ));

  // Do we want parents?
  if ($controls['show_parents'] && $term->depth > 0) {
    $parent_list = array();
    $parents = taxonomy_get_parents_all($term->tid);

    // Get rid of self;
    unset($parents[0]);
    foreach ($parents as $parent) {
      $parent_list[] = l($parent->name, 'taxonomy/vocabulary/' . $vocabulary->vid, array(
        'fragment' => $parent->tid,
      ));
    }
    $output .= ' <div class="taxonomy-list-parents">[&laquo; ' . implode(' &laquo; ', $parent_list) . ']</div>';
  }

  // Add the counters.
  $output .= $counter;
  $links = array();

  // Do we want edit link?
  if (user_access('administer taxonomy') && $controls['edit_link']) {
    $links['taxonomy-list-edit-link'] = array(
      'title' => 'edit term',
      'href' => 'admin/content/taxonomy/edit/term/' . $term->tid,
      'attributes' => array(
        'title' => t('make changes to this term'),
      ),
      'query' => $controls['destination'],
    );
  }

  // Do we want search link?
  if (user_access('search content') && $controls['search_link']) {
    $links['taxonomy-list-search-term'] = array(
      'title' => t('search for term'),
      'href' => 'search/node/"' . $term->name . '"',
      'attributes' => array(
        'title' => t('search for content using this term'),
      ),
    );
  }

  // Do we want RSS link?
  if ($controls['rss_link']) {
    $links['taxonomy-list-rss'] = array(
      'title' => '<img src="' . base_path() . 'misc/feed.png" alt="rss feed for ' . check_plain($term->name) . '" />',
      'href' => 'taxonomy/term/' . $term->tid . '/' . $controls['max_depth'] . '/feed',
      'attributes' => array(
        'title' => t('create feed for this term'),
      ),
      'html' => TRUE,
    );
  }
  if ($links) {
    $output .= theme('links', $links, array(
      'class' => 'links inline',
    ));
  }
  if ($term->description) {
    $output .= '<div class="taxonomy-list-description">' . check_markup($term->description) . '</div>';
  }
  if ($controls['related']) {
    if ($relations = taxonomy_get_related($term->tid, 'name')) {
      $names = array();
      foreach ($relations as $related) {
        $names[] = l($related->name, 'taxonomy/vocabulary/' . $term->vid, array(), NULL, $related->tid);
      }
      $output .= '<div class="taxonomy-list-related">';
      $output .= '<strong>' . t('Related terms') . '</strong>: ' . implode(', ', $names);
      $output .= '</div>';
    }
  }
  if ($controls['synonyms']) {
    if ($synonyms = taxonomy_get_synonyms($term->tid)) {
      $output .= '<div class="taxonomy-list-synonyms">';
      $output .= '<strong>' . t('Synonyms') . '</strong>: ' . implode(', ', $synonyms);
      $output .= '</div>';
    }
  }
  $output .= '</div>';

  // class="taxonomy-list-item"
  return $output;
}