views_handler_field_term_regcode_tid.inc in Registration codes 7.2
Same filename and directory in other branches
Field handler for terms.
This code is all taken from views_handler_field_term_node_tid.inc.
File
includes/views_handler_field_term_regcode_tid.incView source
<?php
/**
* @file
* Field handler for terms.
*
* This code is all taken from views_handler_field_term_node_tid.inc.
*/
/**
* Class views_handler_field_term_regcode_tid.
*/
class views_handler_field_term_regcode_tid extends views_handler_field_prerender_list {
/**
* Implement option_definition.
*/
public function option_definition() {
$options = parent::option_definition();
$options['link_to_taxonomy'] = array(
'default' => TRUE,
);
$options['limit'] = array(
'default' => FALSE,
);
$options['vids'] = array(
'default' => array(),
);
return $options;
}
/**
* Provide "link to term" option.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_taxonomy'] = array(
'#title' => t('Link this field to its term page'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_taxonomy']),
);
}
/**
* Add this term to the query.
*/
public function query() {
$this
->add_additional_fields();
}
/**
* Attaches taxonomy term data (this is called only once)
*
* @param $values
* An array of raw values.
*/
public function pre_render(&$values) {
$this->aliases['vid'] = 'rid';
$this->field_alias = $this->aliases['vid'];
$vids = array();
foreach ($values as $result) {
if (!empty($result->{$this->aliases['vid']})) {
$vids[] = $result->{$this->aliases['vid']};
}
}
if ($vids) {
$result = db_query("\n SELECT tn.rid AS node_vid, td.*, v.name as vocabulary\n FROM {taxonomy_term_data} td\n INNER JOIN {regcode_term} tn ON td.tid = tn.tid\n INNER JOIN {taxonomy_vocabulary} v ON v.vid = td.vid\n WHERE tn.rid IN (:rids) AND td.vid = :vid\n ORDER BY td.weight, td.name", array(
':rids' => $vids,
':vid' => variable_get('regcode_vocabulary', 1),
));
foreach ($result as $term) {
$this->items[$term->node_vid][$term->tid]['name'] = check_plain($term->name);
$this->items[$term->node_vid][$term->tid]['tid'] = $term->tid;
$this->items[$term->node_vid][$term->tid]['vid'] = $term->vid;
$this->items[$term->node_vid][$term->tid]['taxonomy_vocabulary'] = check_plain($term->vocabulary);
if (!empty($this->options['link_to_taxonomy'])) {
$this->items[$term->node_vid][$term->tid]['make_link'] = TRUE;
$uri = taxonomy_term_uri($term);
$this->items[$term->node_vid][$term->tid]['path'] = $uri['path'];
}
}
}
}
/**
* Renders the item.
*/
public function render_item($count, $item) {
return $item['name'];
}
}
Classes
Name![]() |
Description |
---|---|
views_handler_field_term_regcode_tid | Class views_handler_field_term_regcode_tid. |