
Hi,
I've been trying to construct a list of nodes for my front-page using views. The nodes have multiple attached images via Image Attach.
I want to display a single image, node-title and submitted-date for each node in the view. But as far as I can see, there's no way to limit the number of images from Image Attach in Views.
I've been struggling for ages now trying to figure this out, so I hope I haven't missed something totally obvious!
joeboris
Comments
Comment #1
joachim commentedYes, that's not doable. At least not with the Attached images field.
You might be able to make a view of image nodes instead, with a relationship to their attaching images... but then you'd get multiple copies of each attaching node, so that won't work.
Hmmm... I guess this is a missing feature then! I don't have time to work on this, but I'll consider a patch that adds an image count setting to the field handler options.
Though given that you can't change the order of attached images in the UI, it's going to a bit awkward to work with :/
Comment #2
joeboris commentedBeing able to limit the number of images would be great, even if it isn't possible to order the attached images...
I guess its no small task to make an interface similar to Image Field's Views options, which would be the optimal solution...
Thanks!
joeboris
Comment #3
joachim commented> I guess its no small task to make an interface similar to Image Field's Views options, which would be the optimal solution...
It's not *huge*. Add another option to the UI, using the existing ones as a model. The harder part will be changing the theme code in a nice way.
Comment #4
Drupal Centric commentedI solved this by trimming the field to a maximum length, 450 characters worked for me which displayed just the first image :o)
Comment #5
colinmccabe commentedThis works
if you want to display one image only and don't mind the performance decrease (every image still loads). Also, you need to change image node titles so the desired image rises to the top of the alphabetic image attach list, which can be a pain.
Comment #6
__mb commentedThank you, you saved me a lot of time. Dirty, but works!
Comment #7
joachim commentedIf everyone who's submitted a dirty hack put just the same amount of time into a proper solution, we'd be almost there by now. Drupal only moves forward when people contribute to it, folks :/
Comment #8
rayasa commentedSubmitting a dev patch that provides a UI to control the number of images to display from a view. This is based on Joachim's comment at http://drupal.org/node/1024540#comment-4489114.
Comment #9
joachim commentedThanks rayasa. This is looking good.
Just a few points outlined below...
I'm sure the Views handler options system provides a validation method that goes in the handler class rather than outside it... maybe have a poke around other handlers to see?
Wouldn't it be better to do this at the query level with an SQL LIMIT clause?
Powered by Dreditor.
Comment #10
rayasa commentedThanks. I'll check and move the validation inside the views handler. But, regarding the limit and offset, I did consider changing the query, but I don't think we'll get the same flexibility. Let me know if performance is an issue with image_attach.
Comment #11
mean0dspt commentedcan we move on with this patch? looks like a good feature to me
Comment #12
alansch commentedI've just applied Rayasa's patch to image_attach 6.x-1.1 and as far as I can see, it works fine.
The only minor thing I did in addition to the patch was to tweak the theme css to bump the images apart by a couple of pixels so they don't butt up against each other.
Comment #13
joachim commentedSee my comments in #9 above.
Comment #14
joachim commentedOk so image_attach_limits_validate() should be this instead:
Also the spelling of 'Negetive' needs to be fixed ;)
Comment #15
joachim commentedInsomnia is a wonderful thing. Here's an updated version of the patch.
The only thing I've not looked at is:
> But, regarding the limit and offset, I did consider changing the query, but I don't think we'll get the same flexibility. Let me know if performance is an issue with image_attach.
I guess we were querying them all before anyway. And I don't fancy trying to do a negative offset with SQL LIMIT. If anyone else wants to have a go...
Please could people review the patch -- two good reviews and I'll commit it.
Comment #16
johnlutzTried patch with 6.x-1.2 and am having problems. The new Display Limits aren't saving when I save the view.
Comment #17
joachim commentedViews 2 or 3?
Comment #18
alansch commentedI have also had problems applying joachim's image_attach patch in #15 to version 6.x-1.2
The problem seems to be with a naming conflict between the element names in the options form definition and the key names in the underlying options array.
By combining the #15 patch with rayasa's patch in #8 above, I have come up with the following patch that seems to work fine for me in a recently upgraded Drupal 6.28 installation.
I haven't attempted to try this patch on the 1.x-dev version though.
I hope someone finds this helpful/useful.
Comment #20
alansch commentedAnother try at the patch
Comment #21
joachim commentedThanks!
Setting the status.
Let's see what the testbot says. If another user can then review the patch, I'll commit it.