function taxonomy_entity_index_handler_field_tid::pre_render in Taxonomy Entity Index 7
Run before any fields are rendered.
This gives the handlers some time to set up before any handler has been rendered.
Parameters
array $values: An array of all objects returned from the query.
Overrides views_handler_field_term_node_tid::pre_render
File
- includes/
views/ handlers/ taxonomy_entity_index_handler_field_tid.inc, line 31 - Field handler to display all taxonomy terms of an entity.
Class
- taxonomy_entity_index_handler_field_tid
- @file Field handler to display all taxonomy terms of an entity.
Code
function pre_render(&$values) {
$this->field_alias = $this->aliases['entity_id'];
$entity_ids = array();
foreach ($values as $result) {
if (!empty($result->{$this->field_alias})) {
$entity_ids[] = $result->{$this->field_alias};
}
}
if ($entity_ids) {
$query = db_select('taxonomy_term_data', 'td');
$query
->innerJoin('taxonomy_entity_index', 'tei', 'td.tid = tei.tid');
$query
->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
$query
->fields('td');
$query
->addField('tei', 'entity_id', 'entity_id');
$query
->addField('tei', 'entity_type', 'entity_type');
$query
->addField('tei', 'revision_id', 'revision_id');
$query
->addField('tv', 'name', 'vocabulary');
$query
->addField('tv', 'machine_name', 'vocabulary_machine_name');
$query
->orderby('td.weight');
$query
->orderby('td.name');
$query
->condition('tei.entity_id', $entity_ids);
$query
->condition('tei.entity_type', $this->base_table_info['table']['entity type']);
$query
->addTag('term_access');
$vocabs = array_filter($this->options['vocabularies']);
if (!empty($this->options['limit']) && !empty($vocabs)) {
$query
->condition('tv.machine_name', $vocabs);
}
$result = $query
->execute();
foreach ($result as $term) {
$this->items[$term->entity_id][$term->tid]['name'] = check_plain($term->name);
$this->items[$term->entity_id][$term->tid]['tid'] = $term->tid;
$this->items[$term->entity_id][$term->tid]['vocabulary_machine_name'] = check_plain($term->vocabulary_machine_name);
$this->items[$term->entity_id][$term->tid]['vocabulary'] = check_plain($term->vocabulary);
if (!empty($this->options['link_to_taxonomy'])) {
$this->items[$term->entity_id][$term->tid]['make_link'] = TRUE;
$this->items[$term->entity_id][$term->tid]['path'] = 'taxonomy/term/' . $term->tid;
}
}
}
}