Expected Results:
I add a description to the image and it appears on the node.
When I unselect "list" from an image the image does not appear.

Unexpected Results:
Description & List do nothing.

To replicate:

Drupal 6.19
CCK 6.x-2.8
Filefield 6.x-3.7
Imagefield 6.x-3.7
(Duplicated on fresh install with only these modules and upload enabled as well as on two other sites)

Add filefield with image widget to content. Set list field & description field to enabled. Create new node and upload a image. Set a description for the image and save the node out. The description does not appear on the node. Edit the node and unselect list. Save the node back out. Image still appears on node.

CommentFileSizeAuthor
#1 imagefield.patch1.08 KBDurrok

Comments

Durrok’s picture

StatusFileSize
new1.08 KB

Looking into the module it would appear that imagefield doesn't even check to see if list or description is set. I was able to get this to work like filefield by adding the following to filefield in the theme_imagefiled_image function:

$file = (array) $file;
if($file['list'] == 0) {
  return FALSE;
}
return '<img '. $attributes .' /><div class="imagefield-description">'. $file['data']['description'] .'</div>';

The function now looks like:

function theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  $file = (array) $file;
  if($file['list'] == 0) {
	  return FALSE;
  }
  if ($getsize) {
    // Use cached width and height if available.
    if (!empty($file['data']['width']) && !empty($file['data']['height'])) {
      $attributes['width']  = $file['data']['width'];
      $attributes['height'] = $file['data']['height'];
    }
    // Otherwise pull the width and height from the file.
    elseif (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])) {
      $attributes['width'] = $width;
      $attributes['height'] = $height;
    }
  }

  if (!empty($title)) {
    $attributes['title'] = $title;
  }

  // Alt text should be added even if it is an empty string.
  $attributes['alt'] = $alt;

  // Add a timestamp to the URL to ensure it is immediately updated after editing.
  $query_string = '';
  if (isset($file['timestamp'])) {
    $query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?';
    $query_string = $query_character . $file['timestamp'];
  }

  // Encode the parts of the path.
  $parts = explode('/', $file['filepath']);
  foreach ($parts as $n => $part) {
    $parts[$n] = rawurlencode($part);
  }
  $path = implode('/', $parts);

  $url = file_create_url($path) . $query_string;
  $attributes['src'] = $url;
  $attributes = drupal_attributes($attributes);
  return '<img '. $attributes .' /><div class="imagefield-description">'. $file['data']['description'] .'</div>';
}

Patch included.

Durrok’s picture

Status: Active » Needs review
quicksketch’s picture

Status: Needs review » Closed (duplicate)
Durrok’s picture

Sorry I searched for it, guess I wasn't speaking the same language. :)