Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Views Data
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Aug 2008 at 18:11 UTC
Updated:
11 Sep 2008 at 16:52 UTC
Per #300708: Class 'views_handler_field' not found I renamed the file. Since it seemed to do nothing, I added the drupal_set_message you see below and am getting that message, so I know the file is being entered.
Since the 'Term image' item was not included in the fields list anywhere, I changed the group name, as you can see. Still no item, nor a group.
Webchick reported this working. Does Angie have some Views2 magic that escapes me?
<?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() {
drupal_set_message('taxonomy_image_views_data entered.');
// Table definition.
// $data['term_image']['table']['group'] = t('Taxonomy');
$data['term_image']['table']['group'] = t('Taxonomy Image');
// 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 commentedWhat kind of view are you using to test? The definition there will only show your field if you're using a taxonomy term view, so it won't show up for a 'node' view. I have a suspicion that this may be the problem.
Comment #2
nancydruThat's a major problem then, because the users want it primarily when selecting nodes. In 5.x there was nothing but node views and they used this field a lot. Now they want to upgrade since Views2 is now available.
Comment #3
mooffie commentedSo you need to tell Views this table can connent to 'node' as well.
You currently have:
Change it to:
(It's explained in the online help.) Remember to clear Views's cache. Whenever you change some definition (anything inside taxonomy_image_views_data()) you need to clear the cache or else the new definition won't be picked up.
And I think you have some bug in the render() method: You're trying to use some 'tid' column, which isn't really there because nowhere it's loaded. So change:
To:
(Because I don't see 'path' is used anywhere.)
And in you render() method replace every `$values->tid` with `$tid`. At the start of that method add `$tid = $values->{$this->field_alias};`. You probably want to do `if (!$tid) return;` as well.
Comment #4
nancydruThank you, Mooffie. I owe you another hug.
Comment #5
mooffie commentedNancy, I've just looked at your CVS commit. There's one `$values->tid` you forgot to replace.
Comment #6
mooffie commented(Hmm... I'll mention this in the issue you linked to.)
Comment #7
merlinofchaos commentedmooffie: Thanks so much for the help here!
NancyDru: Good luck, sounds like you're fairly close here, at least!
Comment #8
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.