Scenario:
In a content type, we have one imagefield with multiple values selected. If we create a view for this content type (teaser view), and have the first img of the imagefield appear, when this first image is clicked, thickbox would display all first images from other nodes. What happens if a user would like to click on the first image of a node, to see the rest (of the multiple values imagefield in the single node)?

/**
 * Implementation of hook_field_formatter().
 */
function thickbox_field_formatter($field, $item, $formatter) {
  if (module_exists('imagefield') && module_exists('imagecache')) {
    if (empty($item['fid'])) {
      return '';
    }
    $file = _imagefield_file_load($item['fid']);
    if (strpos($formatter, 'thickbox][') !== false) {
      list($null, $namespace) = explode('][', $formatter, 2);
      $rules = _imagecache_get_presets();
      if (in_array($namespace, (array) $rules)) {
-      return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title']);
+        return theme('imagefield_image_imagecache_thickbox', $namespace, $field, $file['filepath'], $item['alt'], $item['title'], $item['nid']);
      }
    }
  }
}

/**
 * Implementation of theme_imagefield_image_imagecache_thickbox().*/
-function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title, $attributes = NULL) 
+function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title, $nid, $attributes = NULL) {
  $attributes = drupal_attributes($attributes);
  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
  $image = '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" '. $attributes .' />';
  return l($image, file_create_url($path), array('title' => $title, 'class' => 'thickbox', 'rel' => $nid), NULL, NULL, FALSE, TRUE);
} 

This way, all images the belong to a node will be assigne with the rel = node number, and rendered in group accordingly.

Thanks.

Comments

frjo’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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