2 // $Id: views_handler_field_taxonomy.inc,v 1.3 2009/01/30 00:01:42 merlinofchaos Exp $
5 * Field handler to provide simple renderer that allows linking to a taxonomy
8 class views_handler_field_taxonomy extends views_handler_field {
10 * Constructor to provide additional field to add.
12 * This constructer assumes the term_data table. If using another
13 * table, we'll need to be more specific.
15 function construct() {
17 $this->additional_fields['vid'] = 'vid';
18 $this->additional_fields['tid'] = 'tid';
21 function option_definition() {
22 $options = parent::option_definition();
23 $options['link_to_taxonomy'] = array('default' => FALSE);
28 * Provide link to taxonomy option
30 function options_form(&$form, &$form_state) {
31 parent::options_form($form, $form_state);
32 $form['link_to_taxonomy'] = array(
33 '#title' => t('Link this field to its taxonomy term page'),
34 '#description' => t('This will override any other link you have set.'),
35 '#type' => 'checkbox',
36 '#default_value' => !empty($this->options['link_to_taxonomy']),
41 * Render whatever the data is as a link to the taxonomy.
43 * Data should be made XSS safe prior to calling this function.
45 function render_link($data, $values) {
46 if (!empty($this->options['link_to_taxonomy']) && !empty($values->{$this->aliases['tid']}) && $data !== NULL && $data !== '') {
47 $term = new stdClass();
48 $term->tid = $values->{$this->aliases['tid']};
49 $term->vid = $values->{$this->aliases['vid']};
50 $this->options['alter']['make_link'] = TRUE;
51 $this->options['alter']['path'] = taxonomy_term_path($term);
56 function render($values) {
57 return $this->render_link(check_plain($values->{$this->field_alias}), $values);