There have been several calls to be able to attach several images to a single node. evil_marty suggested a solution in node http://drupal.org/node/81102. I present another solution here.

The patch introduces a new tab 'more images' when you view a node. Clicking the tab will show all the images attached to the node. The image displayed in the node is the first one (as it was before).

Currently you don't see the other images in the form and you cannot delete it, this is a preview patch. I'm going to work on this further tomorrow since I need it for my ecommerce thing.

On the standard install there is a primary key on image_attach.nid, you have to remove it and place it on nid & iid. MySQL statements to do this:

ALTER TABLE image_attach DROP PRIMARY KEY;
ALTER TABLE image_attach ADD PRIMARY KEY (nid, iid);

Suggestions welcome!

CommentFileSizeAuthor
#8 image_attach.module7.77 KBJax
image_attach_1.patch1.6 KBJax
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jax’s picture

Assigned: Unassigned » Jax

Assigning to myself since I'm going to continue to work on this.

dp-1’s picture

hi,
Thanks, I will test it and give you my feedback.

Jax’s picture

The patch above is just a proof of concept. I'm currently altering the form so that you can see/delete the extra images as well. Other changes:

  • In the more images it displayes the images with "theme('image_teaser', $node);", so you can navigate to the full image. This will need a block to go back to the product (node) you were viewing.
  • I think the themeing is a bit off in the current image_attach module. When you see a teaser of a node with an attached image, clicking the image will bring you to the node (good!) but when viewing the node clicking the image should bring you to the image. I'll change this in a later version, first I'll try to implement the multiple images without tinkering on themeing/linking.

I'll provide a more complete patch by the end of the day (CET).

marcoBauli’s picture

Thank you Jax, this is very useful indeed!

Just for your knowledge, there's a module called Image Tab that does something similar...maybe is worth a look if you didn't already ;)

dp-1’s picture

Hi,
That's looks good. I will look at that but i am using 4.7 have no time to wait for patch. My small suggestion is users feel confused with two types, i mean one upload an image and other attach image, Can't we remove image upload and go with attach image only?
Regards.

Jax’s picture

The "Image Tab" indeed seems to do something similar but the code is in a state of mixed 4.6 & 4.7 and it uses also a table to link images to nodes. It also has other options than image_attach. I'll look at it further and try to incorporate some of the ideas in here. Or maybe upgrade that module to 4.7 in stead of adding similar functionality to image_attach.

Anyway, I wasn't able to finish it yesterday will work on it further the coming days and deliver something that works.

dp-1’s picture

I created a ugly phptemplate function to display all images of the node insteadof attachment list. Here is the code:

function phptemplate_upload_attachments($files){
$header = array(t('Images'));
$rows = array();
foreach($files as $file){
if($file->list){
 $href = '<img src="./' . file_create_path($file->filepath) . ' "/>';
        $rows[] = array($href, null);
    }
  }
  if (count($rows)) {
    return theme('table', $header, $rows, array('id' => 'attachments'));
  }


return;  

}
Jax’s picture

FileSize
7.77 KB

A new preview version. This one shows the images in the form and allows you to delete them. The tab displays how many images are available for the node.

Clicking the image brings you to the image node which actually allows you to see the big image and the original (there should be a way to go back to the node which contains the image, I'm thinking either a block which shows the teaser of the node or extra links in the image node or both).

You cannot delete and add a new image in the same submit at the moment, this needs some more work.

I've attached the full module since a lot is being changed. I'll provide a patch when I'm done. I think this introduces the basic functionality, now on to cleaning the code and making it useable!

dp-1’s picture

Thanks jax. My small request is can we integrate into slideshow rather show all images?
Regards.

eojthebrave’s picture

This looks really useful. I'm going to try it out and will let you now if I run into any problems. Thanks.

Oto-1’s picture

Title: Attach Multiple Images with image_attach (2) » Invalid argument

I have an error on posting new blog.

warning: Invalid argument supplied for foreach() in HOST/modules/image/contrib/image_attach/image_attach.module on line 61.

Oto-1’s picture

Title: Invalid argument » Attach Multiple Images with image_attach (2)

I have an error on posting new blog.

warning: Invalid argument supplied for foreach() in HOST/modules/image/contrib/image_attach/image_attach.module on line 61.

hanaichigo’s picture

this patch is really great !! thanks Jax
By the way, I had the same problem as Oto. I suggest put '(array)' before '$node->iids' in foreach() at line 60.

Scaramouche’s picture

Awesome work Jax... this patch hits a sweet spot!!

Can i make yet another suggestion? is there a way to make it attach a gallery to a node? because sometimes you need to have the pictures sorted by category, and image_gallery is really great with that.

For instance, you create your node, then you create a gallery and add all images to that gallery. And then you attach the gallery to the node, and have the all images tab show all the images in the gallery.

Plus, i don't know if this goes here or somewhere else, but when i go to the all images tab, all the pictures are right next to each other with no space in between. Is this handled in here or in the theme?

Keep up the good work.

Jax’s picture

i don't know if this goes here or somewhere else, but when i go to the all images tab, all the pictures are right next to each other with no space in between. Is this handled in here or in the theme?

The last function in the module image_attach_show_all() builds the view for the "All Images" tab. It uses the image_teaser theme function (theme_image_teaser in image.module). Basically it just concatenates the teasers for the images.

So to modify it you could modify the theme_image_teaser in your theme or alter image_attach_show_all. If you'd change line 226

$output .= theme('image_teaser', $node);

to

$output .= theme('image_teaser', $node) . "<br/>";

the images would be under each other in stead of next to each other.

Play around with that line or the theme_image_teaser in image.module to see how it works.

NikLP’s picture

That would be bad - you should ensure the output renders sufficient classes/ids so that you can use CSS to control the presentation.

In this case you could just float them and it would have the same effect.

stanbroughl’s picture

subscribing

oemb29’s picture

Hi everbybody:

I need the path for 5.0, please any notice send a comment.

Thanks

Hetta’s picture

Status: Needs work » Closed (duplicate)