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

merlinofchaos’s picture

What 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.

nancydru’s picture

That'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.

mooffie’s picture

users want it primarily when selecting nodes

So you need to tell Views this table can connent to 'node' as well.

You currently have:

  $data['term_image']['table']['join'] = array(
     ...blah blah blah...
  );

Change it to:

  $data['term_image']['table']['join'] = array(
     ...blah blah blah...

     // Tell Views we can join with 'node'
    'node' => array(
      'left_table' => 'term_node', // or 'term_data'
      'left_field' => 'tid',
      'field' => 'tid',
    ),
  );

(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:

 $data['term_image']['path'] = array(

To:

 $data['term_image']['tid'] = array(

(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.

nancydru’s picture

Status: Active » Fixed

Thank you, Mooffie. I owe you another hug.

mooffie’s picture

Nancy, I've just looked at your CVS commit. There's one `$values->tid` you forgot to replace.

mooffie’s picture

(Hmm... I'll mention this in the issue you linked to.)

merlinofchaos’s picture

mooffie: Thanks so much for the help here!

NancyDru: Good luck, sounds like you're fairly close here, at least!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.