Introduction / Use Case
One of my pages has a "news" page where every post is accompanied by a picture. To be able to reuse the Images in several posts I decided to just reference the image by ID instead of embedding the file directly. This also gives me the possibility to replace the images with an updated version without touching the posts. As my news posts are custom content types I chose the nodereference field and wrote a small template that displays the referenced images embedded. Of course, letting the user input the node id is unthinkable. img_assist would be perfect for it, as it also gives you the possibility to upload and reference new pictures on the fly.
Idea
CCK differenciates between Field Types and Widgets. A field type is the model, that realizes saving and handling of the data, whereas a widget is what is displayed in the Node Formular. So what I did is write a new widget for the nodereference type that fills in a readonly input field with the help of img_assist. It shows you only the thumb browser and inserts the image id when you click on an image. I'm currently writing the widget to show you the thumbnail in the node form and still need to add support for multiple images and editing.
Discussion
What I want to know now is
- would anybody else be interested in this? (so i would upload it here)
- do you think it makes sense to reuse the nodereference field or should i write a complete field (which would give the advantage that I could package a template to display the image)
- if people are interested, would you consider adding it to img_assist or should it be a contrib module?
Comments
Comment #1
sunI am interested and I'd love to see this in Image Assist. A new widget (as well as probably a field formatter) for the Nodereference field type makes sense, but I do not understand what you meant with "template to display the image" to answer this properly - can you elaborate on this?
6.x-3.x is where we will rewrite the whole module in a more agile approach. This is a perfect timing, because I would even be open to add a partially working feature, or committing incremental patches.
Comment #2
scroogie commentedAh, I completely forgot about the formatters. With "template to display the image" i meant that by default, a nodereference field is only shown as a link to the node. I wrote a node-mycontenttype.tpl.php to display the thumbnail on the post instead. But your right of course, implementing a formatter is a much nicer way to do it.
Comment #3
sunGreat. If you want to discuss this, feel free to ping me in #drupal-wysiwyg.
Comment #4
scroogie commentedOk, I got this running now, even with a nice image preview in the editing form. It will probably take me some time to refactor and to prepare a patch of it, though.
Comment #5
scroogie commentedI'm still tinkering with the idea of a seperate "img_assist field type", because it would give us more flexibility and configuration options. I think I'm going to try writing a field type in a seperate drupal installation to see how it works out.
Comment #6
zoo33 commentedGreat idea!
The benefit of reusing nodereference IMO would be that your data would still be intact if you decided to uninstall img_assist. Shouldn't a custom widget and formatter be sufficient?
Comment #7
scroogie commentedSorry for delaying this for so long. I was very busy recently and didn't have time to work on it at all.
I need some input on it from your site.
For the nodereference, we don't need to show the "properties" page. In my current version I pass a parameter to img_assist to let it know that it's called from a CCK nodereference field and in that case attach a jquery click() event to the picture to preliminary exit the popup. Now comes the question. I currently do this from the img-assist-browser-thumbnail.tpl.php, which is of course not the right way to do it. But what is actually the right way? Should I perhaps create a JS file like for an editor and do this in initLoader()?
Comment #8
sunYou need to add a separate JavaScript for this, containing a Drupal.behavior that gets automatically attached to the output when the popup page has been loaded completely. You need two behaviors (which can live in one JS file):
a) for the page containing the CCK widget to attach the modal/popup behavior and
b) for the modal/popup page to attach/override the onclick event for images in the view.
Regarding b) you additionally need a trigger for this behavior, since I believe that you do not want to implement a different popup window handler and image browser for this feature. So, there must be something along the lines of a query string or a flag in Drupal.settings that triggers the additional behavior and thereby shortcuts the click handler to directly return the image into the parent window/page.
Comment #9
twodI'm not exactly sure what you guys are talking about, but it does sound interesting and I'd love to help once there's code to dig into!
Comment #10
egfrith commentedI'm very interested in this idea too, though don't have time to work on it at the moment.