Run before any fields are rendered.
This gives the handlers some time to set up before any handler has been rendered.
$values: An array of all objects returned from the query.
Overrides FieldPluginBase::pre_render
function pre_render(&$values) {
$vocabularies = entity_load_multiple('taxonomy_vocabulary');
$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
->orderby('td.weight');
$query
->orderby('td.name');
$query
->condition('tn.nid', $nids);
$query
->addTag('term_access');
$vocabs = array_filter($this->options['vids']);
if (!empty($this->options['limit']) && !empty($vocabs)) {
$query
->condition('td.vid', $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_vid'] = $term->vid;
$this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($vocabularies[$term->vid]
->label());
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;
}
}
}
}