I've written a patch against this module that allows users to select a view to use for setting images for a taxonomy term. My use case for this is image galleries, and allowing the users to set the default image using a cck field on the node and filter on that field.

It depends on the embed_views module.

Below are also instructions for how to create a view to use with taxonomy image:

Step 0: Install the <a href="http://drupal.org/project/embed_views">embed_views</a> module.

Step 1: Create a new view of view type 'node'

Step 2: Set the following settings on the view
  Style: Unformatted
  Row style: Fields
  Items to display: 1
  Use pager: No
  More link: No

Step 3: Add a field to the view - note that this field should be the image to be displayed as the term image.
  Select the format 'Path to File'.
  Set the label = None.
  There should only be a single display field in this view, if you need to add other fields for whatever reason, set their "Exclude from display" flag

Step 4: Add the filters you need
  You'll probably want to add a filter on the "Taxonomy: Vocabulary" as well.

Step 5: Add an argument 'Taxonomy: Term ID'

Step 6: Add a new display of type "Embed" and save the view.

Step 7: Configure taxonomy image
  In site configuration -> taxonomy image check the box 'Use a view to select the term images' then select the view you just created.
  You may need to clear your cache for the images to show up.

Comments

hadsie’s picture

StatusFileSize
new3.91 KB

I noticed a minor issue in the patch. Here's the new version.

shaiss’s picture

Thank you for the how to. I folowed everything and applied the patch. How are you using your newly created view?

hadsie’s picture

Basically I'm using taxonomy image to make photo galleries. A user can select a photo in the gallery (i.e. term) to be the main gallery image (i.e. the image chosen for the taxonomy image term). I then have a view that filters on all images in that particular term sorted by the sticky bit and limits the results to just 1 value. That's the view for the taxonomy image selection and it's been working relatively well for me.

freddyseubert’s picture

First off, thanks for patch and description. I also want to display image galleries based on taxonomy, tax. images and tax. list.
Now I have one big problem:
I created the view according to your description and configured the module Taxonomy Image to use the output from that view. But if I browse to my gallery list, there are no images displayed.

I'll post you some more information and hope, that you can give me a hint what to do:

Drupal 6.16
Taxonomy Image 6.x-1.x-dev (2009-May-02)
Taxonomy List 6.x-1.3

The export of the view generating the image path:

$view = new view;
$view->name = 'galeriebild';
$view->description = 'Gibt ein Bild der Galerie zur Anzeige in der Galerieübersicht aus.';
$view->tag = 'Bildergalerien';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Standards', 'default');
$handler->override_option('relationships', array(
  'nid' => array(
    'label' => 'Image file',
    'required' => 1,
    'image_size' => array(
      'thumbnail' => 'thumbnail',
    ),
    'id' => 'nid',
    'table' => 'image_node',
    'field' => 'nid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'filepath' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '/mysubdir/[filepath]', // I tried this with only the subdir and with the full path to the image...
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_file' => 0,
    'exclude' => 0,
    'id' => 'filepath',
    'table' => 'files',
    'field' => 'filepath',
    'relationship' => 'nid',
    'override' => array(
      'button' => 'Übersteuern',
    ),
  ),
));
$handler->override_option('sorts', array(
  'created' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'Alle',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '8' => 0,
      '9' => 0,
      '4' => 0,
      '10' => 0,
      '5' => 0,
      '6' => 0,
      '7' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_image_size' => '_original',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'image' => 0,
      'forum' => 0,
      'panel' => 0,
      'artikel' => 0,
      'aufgabe' => 0,
      'beschlussprotokoll' => 0,
      'gruppe' => 0,
      'mass_contact' => 0,
      'page' => 0,
      'termin' => 0,
      'todo' => 0,
      'umfrage' => 0,
      'wiki' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '4' => 4,
      '2' => 0,
      '1' => 0,
      '3' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
    ),
    'validate_argument_is_member' => 'OG_VIEWS_DO_NOT_VALIDATE_MEMBERSHIP',
    'validate_argument_group_node_type' => array(
      'gruppe' => 0,
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'vid' => array(
    'operator' => 'in',
    'value' => array(
      '4' => '4',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'vid',
    'table' => 'term_data',
    'field' => 'vid',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 1);
$handler = $view->new_display('embed', 'Embed', 'embed_1');

Is it possible, that the module has changed since you created the patch above, even if the patch applied cleanly?

*UPDATE:
Here's the generated HTML in my case: <div class="taxonomy-list-item taxonomy-list-term-37"><ul class="links"><li class="taxonomy-list-image first last"><a href="/wissensmanagement/bildergalerien/berlin"></a></li></ul><a name="37"></a><a href="/wissensmanagement/taxonomy/term/37/all" class="taxonomy-list-term">Berlin</a><div class="taxonomy-list-term-count">(6)</div></div></td>

And in addition to that I should say, that the images are displayed correctly by assigning them directly to a term (without using a view).

Thanks in advance, Freddy

hadsie’s picture

I think you'll need to flush caches in order for the image to be refreshed. That could be the problem.

freddyseubert’s picture

Wow, thanks for such a quick reply! I've deactivated caching on my testsystem and in addition flushed the caches all the way... Any other possible way to get this working?

freddyseubert’s picture

Ah, now I know, why it didn't work. After patching the file taxonomy_image.module, line 256 reads

<?php
 $result
= preg_replace('/Export|Edit|Clone/', '', $result);
?>

But if you are running a localized system (in my case German) the admin links of views are no longer called "Export", "Edit" or "Clone". So I commented out this line and added the now localized links.

<?php
// $result = preg_replace('/Export|Edit|Clone/', '', $result);
$result = preg_replace('/Bearbeiten|Exportieren|Duplizieren/', '', $result);
?>

Now it works like a charm - thanks for your support anyway!

I thought, I'd post this workaround here for other people, who want to use your patch together with a localized views-module. But if there is a way to pull the localized strings out of the db instead of hardcoding them to the module file, this would be even better :)

hadsie’s picture

hmmm... yeah. I guess the regex should be built using t() in that patch instead. that particular part is pretty ugly as well. and I wonder if there's a way to get rid of it altogether.