1 views_handler_field_term_node_tid.inc views_handler_field_term_node_tid::pre_render(&$values)

Run before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

$values: An array of all objects returned from the query.

Overrides views_handler_field::pre_render

File

core/modules/taxonomy/views/views_handler_field_term_node_tid.inc, line 89
Definition of views_handler_field_term_node_tid.

Class

views_handler_field_term_node_tid
Field handler to display all taxonomy terms of a node.

Code

function pre_render(&$values) {
  $this->field_alias = $this->aliases['nid'];
  $nids = array();
  foreach ($values as $result) {
    if (!empty($result->{$this->aliases['nid']})) {
      $nids[] = $result->{$this->aliases['nid']};
    }
  }

  if ($nids) {
    $query = db_select('taxonomy_term_data', 'td');
    $query->innerJoin('taxonomy_index', 'tn', 'td.tid = tn.tid');
    $query->fields('td');
    $query->addField('tn', 'nid', 'node_nid');
    $query->addField('td', 'vocabulary', 'vocabulary');
    $query->orderby('td.weight');
    $query->orderby('td.name');
    $query->condition('tn.nid', $nids);
    $query->addTag('taxonomy_term_access');
    $vocabs = array_filter($this->options['vocabularies']);
    if (!empty($this->options['limit']) && !empty($vocabs)) {
      $query->condition('td.vocabulary', $vocabs);
    }
    $result = $query->execute();

    foreach ($result as $term) {
      $this->items[$term->node_nid][$term->tid]['name'] = check_plain($term->name);
      $this->items[$term->node_nid][$term->tid]['tid'] = $term->tid;
      $this->items[$term->node_nid][$term->tid]['vocabulary'] = $term->vocabulary;

      if (!empty($this->options['link_to_taxonomy'])) {
        $this->items[$term->node_nid][$term->tid]['make_link'] = TRUE;
        $this->items[$term->node_nid][$term->tid]['path'] = 'taxonomy/term/' . $term->tid;
      }
    }
  }
}