*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.
| Comment | File | Size | Author |
|---|---|---|---|
| thickbox.module.imagefield_0.patch | 2.06 KB | yojoe |
Comments
Comment #1
moshe weitzman commentedthis seems like a terrific addition. cck images + thickbox is just sweet.
Comment #2
FiReaNGeL commentedIts a feature most of us would end up coding anyway, so +1 for including it, very useful!
Comment #3
frjo commentedLooks 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.
Comment #4
Wolfgang Reszel commentedHmmm ... 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.
Comment #5
frjo commentedCommitted to HEAD, please try it out and report back here.
Comment #6
abramo commentedI 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():
2.- add javascript on page template:
this resolves the issue temporarily, but more sophisticated care should be taken from within the module regarding empty image fields.
Comment #7
abramo commentedcorrection:
1.- add in thickbox.module, in Implementation of theme_imagefield_image_imagecache_thickbox():
Comment #8
FiReaNGeL commentedWhen 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?
Comment #9
FiReaNGeL commentedTested 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!
Comment #10
abramo commentedI 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
Comment #11
eaton commentedThis 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.
Comment #12
abramo commented"Formatter 'variations,' or something like that"
brilliant!!
Comment #13
eaton commentedWell, 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.
Comment #14
jm9 commentedI'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:
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:
For some reason, I can't get CCK/imagefield to invoke the custom formatter.
TROUBLESHOOTING:
Any hints / suggestions?
JM
Comment #15
abramo commenteduse imagecache module with imagefield & thickbox
Comment #16
jm9 commentedThanks 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
Comment #17
abramo commentedfor single-image imagfields, just insert in your page template something like:
you need nothing more.
I have no experience with multiple-image imagefields/imagecache/thickbox combination and have no idea whether thickbox functions this way.
Comment #18
diegogers commentedexcellent 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
Comment #19
designwork commentedHi
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
Comment #20
designwork commentedFound 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
Comment #21
yojoe commentedComment #22
frjo commentedComment #23
(not verified) commented