--- ./views/modules/taxonomy/views_handler_field_term_node_tid.inc-orig 2009-01-15 06:01:24.000000000 -0700 +++ ./views/modules/taxonomy/views_handler_field_term_node_tid.inc 2009-01-18 13:20:32.000000000 -0700 @@ -18,8 +18,10 @@ class views_handler_field_term_node_tid function option_definition() { $options = parent::option_definition(); + $options['imagecache_preset'] = array('default' => ''); $options['link_to_taxonomy'] = array('default' => TRUE); $options['limit'] = array('default' => FALSE); + $options['image'] = array('default' => FALSE); $options['vids'] = array('default' => array()); return $options; @@ -58,6 +60,31 @@ class views_handler_field_term_node_tid '#process' => array('expand_checkboxes', 'views_process_dependency'), '#dependency' => array('edit-options-limit' => array(TRUE)), ); + + // If ImageCache module is found, add its presets as available options + // for how to display the image. + if (module_exists('imagecache') && module_exists('taxonomy_image')) { + $form['image'] = array( + '#type' => 'checkbox', + '#title' => t('Use Image Taxonomy'), + '#default_value'=> $this->options['image'], + ); + + $raw_presets = imagecache_presets(); + $presets[''] = t('Default'); + foreach ($raw_presets as $preset_id => $preset_info) { + $preset = $preset_info['presetname']; + $presets[$preset] = $preset; + } + $form['imagecache_preset'] = array( + '#type' => 'select', + '#title' => t('ImageCache preset'), + '#options' => $presets, + '#default_value' => $this->options['imagecache_preset'], + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array('edit-options-image' => array(TRUE)), + ); + } } /** @@ -92,5 +119,40 @@ class views_handler_field_term_node_tid } } } + + /** + * Render field output to the browser. + */ + function render($values) { + if (empty($this->options['image']) || $this->options['image'] == 0) { + return parent::render($values); + } else { + $images = ''; + $field = $values->{$this->field_alias}; + if (!$field) { + return; + } + $tids = array_keys($this->items[$field]); + + foreach ($tids as $tid) { + $image = ''; + // Render image. If ImageCache preset is specified, use it. + if ($this->options['imagecache_preset']) { + $image = taxonomy_image_display($tid, NULL, $this->options['imagecache_preset']); + } + else { + $image = taxonomy_image_display($tid); + } + + // Output image as a link, if option is set. + if ($this->options['link_to_taxonomy']) { + $image = l($image, drupal_get_path_alias(taxonomy_term_path(taxonomy_get_term($tid))), array('html' => TRUE)); + } + $images .= $image; + } + + return $images; + } + } }