You are here

function ctools_term_list_content_type_render in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 plugins/content_types/term_context/term_list.inc \ctools_term_list_content_type_render()

File

plugins/content_types/term_context/term_list.inc, line 25

Code

function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $context) {
  $term = isset($context->data) ? clone $context->data : NULL;
  $block = new stdClass();
  $block->module = 'term-list';
  $path = empty($conf['path']) ? 'taxonomy/term/%tid' : $conf['path'];
  if (strpos($path, '%tid') === FALSE) {
    if (substr($path, -1) != '/') {
      $path .= '/';
    }
    $path .= '%tid';
  }
  $options = ctools_admin_term_list_options();
  $skip = array();
  if ($term) {
    $block->title = $options[$conf['type']];
    $block->delta = $conf['type'];
    switch ($conf['type']) {
      case 'related':

        // @todo this no longer exists, must be done with Field API.
        // $terms = taxonomy_get_related($term->tid);
        break;
      case 'child':
      default:
        if (!empty($conf['include_current_term'])) {
          $terms[] = $term;
        }
        $terms = taxonomy_get_children($term->tid);
        break;
      case 'top':
        $terms = taxonomy_get_tree($term->vid, 0, 1);
        break;
      case 'parent':
        $terms = taxonomy_get_parents($term->tid);
        if (!empty($conf['include_current_term'])) {
          $terms[] = $term;
        }
        $block->title = count($terms) == 1 ? t('Parent term') : t('Parent terms');
        break;
      case 'sibling':
        $parent = db_query('SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid', array(
          ':tid' => $term->tid,
        ))
          ->fetchField();
        if ($parent) {
          $terms = taxonomy_get_children($parent, $term->vid);
        }
        else {
          $terms = taxonomy_get_tree($term->vid, 0, 1);
        }
        $skip[$term->tid] = $term->tid;
        break;
      case 'synonyms':

        // FIXME this no longer exists, must be done with Field API
        //        $terms = taxonomy_get_synonyms($term->tid);.
        break;
    }
    if (!empty($terms)) {
      foreach ($terms as $related) {
        if (empty($skip[$related->tid])) {
          $items[] = l($related->name, str_replace('%tid', $related->tid, $path), array(
            'rel' => 'tag',
            'title' => strip_tags($related->description),
          ));
        }
      }
      if (!empty($items)) {
        $block->content = theme('item_list', array(
          'items' => $items,
          'type' => $conf['list_type'],
        ));
      }
    }
  }
  else {
    $block->content = t('Term description goes here.');
    $block->delta = 'unknown';
  }
  return $block;
}