*I moved the patch here, because it should be included in thickbox.module and not in imagefield.module. See http://drupal.org/node/112683 for further information on the discussion, where this patch belongs to.*

This is a small but very useful patch to use imagecache.module and thickbox.module together in Drupal 5 for formatting (rendering) CCK-imagefields. If imagefield.module, imagecache.module and thickbox.module are available, then for every imagecache preset an additional imagache+thickbox formatter is available. Let's say you have defined an imagecache preset named 'thumbnail', then you'll automatically get an additional formatter named 'Thickbox: thumbnail'. If you choose this formatter e.g. for the body, then the imagecache 'thumbnail'-preset is used to show a clickable preview image of the full-size image. If you click the preview, Thickbox is used to nicely overlay the full size image over the current page. If the imagefield has multiple images, they are treated like a gallery and thickbox displays 'Next' and 'Prev' buttons.

This patch uses hook_field_formatter_info(), hook_field_formatter() and provides a theme_imagefield_image_imagecache_thickbox() function to format the HTML output.

CommentFileSizeAuthor
thickbox.module.imagefield_0.patch2.06 KByojoe

Comments

moshe weitzman’s picture

this seems like a terrific addition. cck images + thickbox is just sweet.

FiReaNGeL’s picture

Its a feature most of us would end up coding anyway, so +1 for including it, very useful!

frjo’s picture

Looks very neat! I'm traveling at the moment but when I return in a couple of weeks I will take a look at this and most likly commit it.

Wolfgang Reszel’s picture

Hmmm ... does not work for me. thickbox_field_formatter_info will never be called. Maybe I misunderstood the description. I went to manage fields and tried to configure my field_image. There are just my normal presets visible.

frjo’s picture

Assigned: Unassigned » frjo
Status: Reviewed & tested by the community » Active

Committed to HEAD, please try it out and report back here.

abramo’s picture

I have tested the inital patch extensively and it works perfect.
this modification has been an excellent idea, very valuable. thanks.

a minor issue was as follows:
when the image field is empty, in MSIE you get the dreaded "default missing image" placeholder (npa.gif) i.e. the little square with the red x. if ex. 10 image fields are empty you get 10 of those (horrible).

this was resolved as follows:

1.- add in thickbox.module, in Implementation of theme_imagefield_image_imagecache_thickbox():

onError="SubstituteDefaultMissingImage()"

2.- add javascript on page template:

<SCRIPT>
if (navigator.appName=="MSIE")
function SubstituteDefaultMissingImage()
{
document.images['default-missing-image'].src = '/resources/images/transparent.gif';
}
else
{
}
</SCRIPT>

this resolves the issue temporarily, but more sophisticated care should be taken from within the module regarding empty image fields.

abramo’s picture

correction:

1.- add in thickbox.module, in Implementation of theme_imagefield_image_imagecache_thickbox():

name="default-missing-image" onError="SubstituteDefaultMissingImage()"
FiReaNGeL’s picture

When there is no image, imagecache shouldnt even output the imagefield field nor any divs. It screws with the padding and margins of the design (little blank space where the image should be). Should we open a new issue for that?

FiReaNGeL’s picture

Tested with the latest version and it works as advertised. Very minor "problem" : if I have a list of nodes with teasers (such as the frontpage) and click an image, it displays properly but shows next/prev links for other pictures on the frontpage. This is not the expected behavior; i'd expect it to show only pictures for that node.

Aside from that, works perfect, thanks a lot!

abramo’s picture

I am also using the latest modules, but the problem exists.

I want to clarify that the image-calling php is hardcoded in the template for the output, and this may be the difference between the above two cases. meaning that an image is called by the template irrespective of whether it exists or not. in a way, it is a "placeholder" php.

example:
- a template has hadcoded three php image requests as follows:

- print $node->field_property_image_1[0]['view']
- print $node->field_property_image_2[0]['view']
- print $node->field_property_image_3[0]['view']

if only a single image has actually been uploaded (say, the first one)
then the browser returns two "default missing images" (the little square with the red cross) in place of the two missing images.

how can the imagecache module be modified in order to return nothing (or even a specific placeholder image of administrator's choice) when no image has been uploaded but the hadrcoded php request is present?

thanks,
abramo

eaton’s picture

This raises an important question; how many formatters is it acceptable to display for a field? Right now, we have the number of presets, with another set for the 'with link' version, and now another set for the 'with thickbox' version. There's no way around it atm, but it seems that some of these more complex fields really do need another dimension for their formatters... Formatter 'variations,' or something like that.

abramo’s picture

"Formatter 'variations,' or something like that"

brilliant!!

eaton’s picture

Well, I mean, the *idea* is awesome, but it also makes actually implementing things hellacious. ;-) I'm not sure how I would even begin to implement something like formatter variations. Heh.

In the meantime, I do approve wholeheartedly about adding thickbox support.

jm9’s picture

I'd like to do some testing with this, but I haven't been able to get it working yet.

I have 5.1 freshly installed with these modules:

  • thickbox.module, v 1.9 (2007/02/17)
  • imagefield.module, v 1.30.2.7 (2007/02/23)
  • content.module, v 1.90.2.36 (2007/01/29)
  • imagecache.module, v 1.19.2.15 (2007/02/21)

I created an Imagecache preset called "thumb"

I added a multi-value imagefield called "photos" to a custom node type called "test" and then added a node with 2 images.

I created a new template file called "node-test-tpl.php" and inserted the following snippet into the content div:

    <?php foreach ($field_photos as $photo) { ?>
     <?php print content_format('field_photos', $photo, 'Thickbox: thumb') ?>
    <?php } ?>

For some reason, I can't get CCK/imagefield to invoke the custom formatter.

TROUBLESHOOTING:

  • Photos show with the default formatter (if I remove 'Thickbox: thumb')
  • I've inserted a debug message in function thickbox_field_formatter(), and it doesn't seem that it's ever being invoked.
  • From what I see in thickbox_field_formatter_info(), 'Thickbox: thumb' seems to be the correct formatter name; but I've also tried 'Thickbox:thumb', 'thickbox: thumb', and 'thickbox:thumb'

Any hints / suggestions?

JM

abramo’s picture

use imagecache module with imagefield & thickbox

jm9’s picture

Thanks for the tip abramo :D

Some example code from a template file that enables thickbox use a specific imagecache preset for an imagefield would be helpful. I haven't been able to trigger thickbox_field_formatter().

Can someone share a good example of this (or am I misunderstanding how this patch works)?

JM

abramo’s picture

for single-image imagfields, just insert in your page template something like:

<?php print $node->field_yourimage[0]['view'] ?>

you need nothing more.

I have no experience with multiple-image imagefields/imagecache/thickbox combination and have no idea whether thickbox functions this way.

diegogers’s picture

excellent combination.

Is't it possible that when you click the thumbnail and the thickbox shows, make it not show the original image but other imagecache preset?

Thanks

designwork’s picture

Title: add imagecache+thickbox formatters to imagefields (CCK) » Not showing the title of an image

Hi

I´m using imagefield, imagecache and thickbox. Every thing works fine I´m just confused why it is not showing the title of the image and the author of the image? I think it´s because auf the construction of the link.

The Link looks like this:
a href="http://www.freelens.ws/dirksway/files/images/02.jpg" class="thickbox" rel="bild"

But in the example of the thickbox page it looks like this:
a href="http://www.freelens.ws/dirksway/files/images/02.jpg" TITLE="Your title" class="thickbox" rel="bild"

So where in the Module I have to change the Link? I would add the $title and $author to show both.

Dirk

designwork’s picture

Found a Solution for it.

just add in the last line of the function theme_imagefield_image_imagecache_thickbox

return a herf..... title="'. ($title) .'" before the class"tickbox" and you will see the title of the image. But i´m not shure if we can add the author name as well?

Dirk

yojoe’s picture

Title: Not showing the title of an image » add imagecache+thickbox formatters to imagefields (CCK)
frjo’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)