• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/taxonomy/views_handler_field_taxonomy.inc

00001 <?php
00002 
00009 class views_handler_field_taxonomy extends views_handler_field {
00016   function construct() {
00017     parent::construct();
00018     $this->additional_fields['vid'] = 'vid';
00019     $this->additional_fields['tid'] = 'tid';
00020     $this->additional_fields['vocabulary_machine_name'] = array(
00021       'table' => 'taxonomy_vocabulary',
00022       'field' => 'machine_name',
00023     );
00024   }
00025 
00026   function option_definition() {
00027     $options = parent::option_definition();
00028     $options['link_to_taxonomy'] = array('default' => FALSE);
00029     $options['convert_spaces'] = array('default' => FALSE);
00030     return $options;
00031   }
00032 
00036   function options_form(&$form, &$form_state) {
00037     $form['link_to_taxonomy'] = array(
00038       '#title' => t('Link this field to its taxonomy term page'),
00039       '#description' => t("Enable to override this field's links."),
00040       '#type' => 'checkbox',
00041       '#default_value' => !empty($this->options['link_to_taxonomy']),
00042     );
00043      $form['convert_spaces'] = array(
00044       '#title' => t('Convert spaces in term names to hyphens'),
00045       '#description' => t('This allows links to work with Views taxonomy term arguments.'),
00046       '#type' => 'checkbox',
00047       '#default_value' => !empty($this->options['convert_spaces']),
00048     );
00049     parent::options_form($form, $form_state);
00050   }
00051 
00057   function render_link($data, $values) {
00058     $tid = $this->get_value($values, 'tid');
00059     if (!empty($this->options['link_to_taxonomy']) && !empty($tid) && $data !== NULL && $data !== '') {
00060       $term = new stdClass();
00061       $term->tid = $tid;
00062       $term->vid = $this->get_value($values, 'vid');
00063       $term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
00064       $this->options['alter']['make_link'] = TRUE;
00065       $uri = entity_uri('taxonomy_term', $term);
00066       $this->options['alter']['path'] = $uri['path'];
00067     }
00068 
00069     if (!empty($this->options['convert_spaces'])) {
00070       $data = str_replace(' ', '-', $data);
00071     }
00072 
00073     return $data;
00074   }
00075 
00076   function render($values) {
00077     $value = $this->get_value($values);
00078     return $this->render_link($this->sanitize_value($value), $values);
00079   }
00080 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1