In #267427: Views2 integration, webchick provided a patch to Taxonomy Image to support Views 2. When I test it, I get:
PHP Fatal error: Class 'views_handler_field' not found in C:\\www\\drupal-6\\sites\\all\\modules\\contrib\\taxonomy_image\\taxonomy_image_views.inc on line 42, referer: http://d6/admin/build/views
Yes, I clear the Views cache every time I visit the Views page.
After reading #239711: Class 'views_handler_field_node' not found, I downloaded the most recent -dev version (Aug 26) and re-tested with the same error. Since that issue mentioned that module order might be involved, I set Taxonomy Image's module weight to 2 higher than Views 2. I still get this error.
AFAICT, there are no other modules at play here. I am using Drupal 6.4, PHP 5.2.0, and MySql 5.0.23.
The exact code is:
<?php
// $Id: taxonomy_image_views.inc,v 1.1.2.1 2008/08/27 16:23:33 nancyw Exp $
/**
* @file
* Views integration for Taxonomy Image module.
*/
/**
* Implementation of hook_views_data().
*/
function taxonomy_image_views_data() {
// Table definition.
$data['term_image']['table']['group'] = t('Taxonomy');
// Joins.
$data['term_image']['table']['join'] = array(
'term_data' => array(
// Links directly to term_data via tid.
'left_field' => 'tid',
'field' => 'tid',
),
);
// Fields.
$data['term_image']['path'] = array(
'title' => t('Term image'),
'help' => t("The image associated with a taxonomy term."),
'field' => array(
'handler' => 'views_handler_field_taxonomy_image',
),
);
return $data;
}
/**
* Field handler to provide an embedded image.
*
* @ingroup views_field_handlers
*/
class views_handler_field_taxonomy_image extends views_handler_field {
/**
* Define options available for this field.
*/
function option_definition() {
$options = parent::option_definition();
$options['imagecache_preset'] = array('default' => '');
$options['link_to_taxonomy'] = array('default' => FALSE);
return $options;
}
/**
* Build option configuration form.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_taxonomy'] = array(
'#title' => t('Link this image to its term page'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_taxonomy']),
);
// If ImageCache module is found, add its presets as available options
// for how to display the image.
if (module_exists('imagecache')) {
$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'],
);
}
}
/**
* Render field output to the browser.
*/
function render($values) {
$image = '';
// Render image. If ImageCache preset is specified, use it.
if ($this->options['imagecache_preset']) {
$image = taxonomy_image_display($values->tid, NULL, $this->options['imagecache_preset']);
}
else {
$image = taxonomy_image_display($values->tid);
}
// Output image as a link, if option is set.
if ($this->options['link_to_taxonomy']) {
$image = l($image, taxonomy_term_path(taxonomy_get_term($values->tid)), array('html' => TRUE));
}
return $image;
}
}
Comments
Comment #1
merlinofchaos commentedYou should place this in MODULENAME.views.inc rather than in your base module; Views will automatically include that file when handlers are needed.
Comment #2
merlinofchaos commentedOr rather than taxonomy_image_views.inc
And you don't need to include the file on your own. Let Views handle it.
Comment #3
nancydruThank you, Earl.
Comment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.