Hello there,
I'm trying to make a site where you can add pictures to a database of cities, so the cities are 'preloaded', and users can then attach images to the cities that they want to contribute to. Each city page will show a set of thumbnails at the bottom of all the images contributed to that city by various users. Users should only be able to delete their own pictures, not everybody elses, and should not have edit permissions for the cities themselves. Images should be nodes in their own right.
I thought that what I had in mind was relatively easy, but after a couple of days of searching and trying to make this work I'm no longer as sure as I was when I started.
Doing this outside of drupal would have been a fairly easy affair, but I very much want to do this the 'drupal way' to check out the potential of the platform. I've had some cryptic hints about how I could achieve this:
"Instead, make each image that is uploaded its own node, with an imagefield and a nodereference field that points back to the city node. You can do some massaging in Form API and hook_links() to make the submit form for your image node auto-populate the city reference field. Then just attach a Viewfield to the city node to list all related image nodes."
To an old hand drupal user that is probably as easy as 1-2-3 but I can't seem to make soup out of it, which makes me feel pretty stupid. I've tried to make a module that fills in the parent field for the node reference according to an article that I found somewhere that plucks the parent node id from the refering URL, but that only gets me lots of error messages on the submit.
Is there anybody out there that would mind taking the time to spell this out for me ? I'm pretty sure that it's possible but for the life of me I can't seem to figure it out.
thanks...
Comments
I'd handle it with tax0nomies, customized views and
an image module or two.
You don't want that cool picture of a city cafe to ONLY reside in your cities story do you? You'll want to give your users the opportunity to also reuse it for your cool "Cafe Fronts" page too, without having to re-upload it.
So, rethink what your "story" is: consider making your Cities page a taxonomy listing which is assembled using:
1) A node that provides some context (however short) for your story.
2) A taxonomy term that allows people to tag images uploaded for that "story"
3) The ability to upload an image
4) Maybe, the ability for the system to recognize that when someone uploads an image on that page, it automagically tags itself with the correct taxonomy term
5) Finally, a "views" report that displays the page in the format you desire. Use the views themeing customization to get the report to display the way you want.
6) Of course you'll need a module to help you upload/maintain the images. I currently don't have a favorite, though I've found IMCE to be the easiest for novice users to understand (plus, I like how it creates by default a separate image directory for each user.
You might also consider one of the gallery type modules to help your organize your images (but I don't have much experience with any of them beyond poking around).
In conclusion: carefully think about whether you should be using a "node" as your organizing entity for this function. You might be better off looking at "envelope" functions like views or galleries instead.
why a parent-child relationship
The reason for the parent / child relationship is that this site is pretty strict in the kind of linkages that it allows between various objects (cities, people, pictures). The main 'key' is for instance a city, and then on the city page people can see the images that others have uploaded and add their own. It's a pretty simple concept really. So, the 'cool cafe fronts' scenario will not apply today or in the future, images are strict children of their parent nodes, there will never be any 'reuse' of images.
I had not checked out IMCE yet, but I'll install it and see what it does.
When you look at this problem conceptually it is quite similar to the 'comments' feature that is in the drupal core, only instead of a comment text you upload a picture.
Hm, maybe I could modify the comments module to turn it into an 'attach pictures to this node' module ?
ok, I have it working
It took a bit of fiddling but I have it working. The solution I ended up with was using a slightly modified 'node_image' module in combination with nodeaccess. Nodeaccess is used to split delete / edit rights for the nodes that the images are going to be attached to, a small modification to node_image (one line change, where it decides to display the Images tab you remove the 'edit rights' check) displays the image tab if the user does not have 'edit' rights for that node but is allowed to upload new images.
That way users that do not have edit rights for a node can still upload images associated with that node.
To improve it a bit further I added another small modification to the node_image module, where it builds up the list of images to display on the image tab I have changed it so that it only lists the images that the user owns or has deletion rights to, like that people can't screw up each others image captions.
If you need this functionality (allowing random logged in users to 'annotate' nodes with images) then you may download the modified node_images module here:
http://themodularcompany.com/downloads/node_images.tar.gz
I don't think that the mods lead to security issues, but in case I've missed something please drop me a line
or reply to this posting.
best regards,
Jacques Mattheij