Hey there,

I was looking for a solution to the lists that appear in places of images for imagefields and came across a http://anexusit.com/blog/drupal-how-enable-filefield-image-print-images-print-module-htmlpdf">post with a template.php hook that you can use to make the filefield list be an actual image when the filefield is an image versus an actual file such as txt, doc, etc. If this seems like a desirable feature I could go ahead and roll up a module patch for it, may end up doing that and posting it in a follow up. I personally think it might be a nice touch for the editablefields module but others might not feel the same way.

<?php
/**
 * Theme function for the 'generic' single file formatter.
 */
function mytheme_filefield_file($file) {
  // Views may call this function with a NULL value, return an empty string.
  if (empty($file['fid'])) {
    return '';
  }

  $path = $file['filepath'];
  $url = file_create_url($path);

  $options = array(
    'attributes' => array(
      'type' => $file['filemime'] . '; length=' . $file['filesize'],
    ),
  );

  // Use the description as the link text if available.
  if (empty($file['data']['description'])) {
    $link_text = $file['filename'];
  }
  else {
    $link_text = $file['data']['description'];
    $options['attributes']['title'] = $file['filename'];
  }
  
  
  if(strstr($file['filemime'],'image')) {
    // change the_preset to your imagecache preset's machine readable name
    $image = theme('imagecache','the_preset',$path); 
    return '
' . $image .'
';
  } else { 
    $icon = theme('filefield_icon', $file);
    return '
'. $icon . l($link_text, $url, $options) .'
';
  }  
}
?>

This goes in your theme's template.php -- Don't forget to change out "mytheme" in the function name for your actual theme name and "the_preset" with the machine readable name of the imagecache preset that you would like to appear by default. Perhaps this can be improved by hooking what is set for Display Fields for an imagefield.

CommentFileSizeAuthor
#1 editablefields.vishun.patch2.3 KBvishun

Comments

vishun’s picture

Title: Imagefields: show images instead of a list » Imagefield compatibility with editablefields
StatusFileSize
new2.3 KB

Since the previously posted information is generally applicable to trying to make Imagefields more compatible with the editablefields module, I have changed the title accordingly.

I have gone ahead and converted this template.php hook into something that can be done right from the editabelfields module using hook_theme_registry_alter() thanks to hefox on IRC. This patch should modify the output of imagefield filefields so that it shows their imagecache preset instead of the normal filefield list. There is currently a flaw with this patch that I just noticed in that the actual imagecache preset is currently hardcoded as "beer_small" which you will need to change out to one of your imagecache presets.

Presently this should make it so that when you view a clicktoedit style imagefield it should show the actual image and then when clicked or the the edit link is clicked it should load up the upload form and allow you to browse and upload. This does indeed work however there are some fail points currently. When the image finishes uploading, the AHAH form stays put and the editablefield hides itself. The best case scenario and goal in my opinion is retrieving and showing the newly uploaded image, but this is where I've lost traction on how to go about that.

Issues addressed by this patch:

  • Imagefield/filefield upload form no longer hides when the browse or upload button is clicked
  • Displays an imagecache preset for an imagefield instead of the default filefield list

Issues that still need to be addressed:

  • Making the imagecache preset dynamic, if possible
  • Removing the imagefield AHAH form and displaying the newly uploaded image
  • The Remove button and functionality is relatively broken (not related to the patch, only visible when there is already an image attached to the imagefield)

Any input or suggestions related to this patch and the issues that still need addressing would be greatly appreciated.

Thanks.

gateway69’s picture

I would love to have this ability, I have tried to allow users to replace or add images to products if their are the wrong image or was just missing one..

Any Dev have any thoughts on what do do in this situation?

andreiashu’s picture

Because of the way CCK was done I don't really see any way of doing this other than overriding the theme function as in vishun's patch. This is very hackish though and it will bring more potential problems in the future.

I'll have a look at this hopefully during this weekend.

Vishun, thanks for looking into this.

Andrei

gateway69’s picture

Ahh thanks, I am also looking at the patch but cant seem to get it to work fully yet..

let me know if you find out something.. cheers

gateway69’s picture

andreiashu, any chance you had any time to look into this or see how this could be accomplished?

andreiashu’s picture

@gateway69: sorry, not really. I still plan to work on it but I just didn't have time :(

g76’s picture

I would love this feature as well, including the "issues that need to be addressed" from #1. I am not a coder, but would be more than happy to test.

My use case is that I am building a media gallery which I am in hopes can be a feature. One part of the whole thing is I am using hierarchical select for users to add media(image,video,audio) to existing terms(galleries) in a "Media" taxonomy vocab and create new ones on the fly on the node form. Then I have Taxonomy Node creating a "Gallery Info" content type(imagefield and description) with defaults every time a new term is created. I need users to have the option to upload a custom thumbnail and enter a unique description for each gallery on the node and in a view.

Thank you so much for your incredible module, and all your hard work, it is so much appreciated.

gateway69’s picture

anyone make any progress on this? :)

micheleannj’s picture

[wrong thread!]

mengi’s picture

Status: Active » Closed (won't fix)

Per https://drupal.org/node/2148735, 6.x is longer maintained so issue is closed. If you wish to be a maintainer of the 6.x branch please create a new issue.