You are here

function taxonomy_term_depth_handler_field_taxonomy::render_link in Taxonomy Term Depth 7

Find the parent at the desired depth if available. Render whatever the data is as a link to the taxonomy.

Data should be made XSS safe prior to calling this function.

Overrides views_handler_field_taxonomy::render_link

File

includes/taxonomy_term_depth_handler_field_taxonomy.inc, line 47
Field handler to provide the parents of field value terms.

Class

taxonomy_term_depth_handler_field_taxonomy
@file Field handler to provide the parents of field value terms.

Code

function render_link($data, $values) {
  $tid = $this
    ->get_value($values, 'tid');
  if (!empty($tid) && $data !== NULL && $data !== '') {
    $desired_depth = $this->options['desired_depth'];
    $parents_tids = taxonomy_term_depth_get_parents($tid, TRUE);
    $parents_tids[] = $tid;
    $parent_tid = isset($parents_tids[$desired_depth - 1]) ? $parents_tids[$desired_depth - 1] : NULL;
    if ($parent_tid) {
      $parent = taxonomy_term_load($parent_tid);
      $term = new stdClass();
      $term->tid = $parent_tid;
      $data = $parent->name;
      if (!empty($this->options['link_to_taxonomy'])) {
        $term->vid = $this
          ->get_value($values, 'vid');
        $term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
        $this->options['alter']['make_link'] = TRUE;
        $uri = entity_uri('taxonomy_term', $term);
        $this->options['alter']['path'] = $uri['path'];
      }
    }
    else {
      $data = '';
    }
  }
  if (!empty($this->options['convert_spaces'])) {
    $data = str_replace(' ', '-', $data);
  }
  return $data;
}