I was getting erratic links when using the 'link as a node' feature. It's because a file can be in several nodes and it's not a good idea to get the node id value from the table 'file'. Here's a suggestion to correct the problem:

/**
 * Implementation of hook_field_formatter().
 */
function imagecache_field_formatter($field, $item, $formatter, $node) {
  if (empty($item['fid']) && $field['use_default_image']) {
    $item = $field['default_image']; 
  }
  // Views does not load the file for us, while CCK display fields does.
  if (!isset($item['filepath'])) {
    $file = _imagecache_file_load($item['fid']);
    $item = array_merge($item, $file); 
  }
  # FIX:
  $item['nid'] = $node->nid;

  $presetname = preg_replace('/_linked$/', '', $formatter);
  $presetname = preg_replace('/_imagelink$/', '', $presetname); # ericdes
  if ($preset = imagecache_preset_by_name($presetname)) {
    return theme('imagecache_formatter', $field, $item, $formatter);
  }
}

function _imagecache_file_load($fid = NULL) {
  // Don't bother if we weren't passed an fid.
  if (isset($fid) && is_numeric($fid)) {
    $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
    $file = db_fetch_array($result);
    unset($file['nid']); # FIX: That value is a property of that file, many nodes can use that file. 
  }
  return ($file) ? $file : array();
}

Comments

dopry’s picture

Status: Active » Postponed (maintainer needs more info)

umm no... only files are only associated to one node in D5, you may be on to something though...
try explaining what it up again so someone can reproduce it and test your solution... also inline code is not an acceptable way to post a patch. Please create a patch!

dopry’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

closed no response from original author and unable to reproduce.