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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Yes, 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 :/

joeboris’s picture

Being 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

joachim’s picture

> 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.

Drupal Centric’s picture

I solved this by trimming the field to a maximum length, 450 characters worked for me which displayed just the first image :o)

colinmccabe’s picture

This works

.views-field-image-attach-images div {
display: none;
}

.views-field-image-attach-images div:first-child {
display: block;
}

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.

__mb’s picture

Thank you, you saved me a lot of time. Dirty, but works!

joachim’s picture

If 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 :/

rayasa’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
FileSize
4.01 KB

Submitting 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.

joachim’s picture

Status: Active » Needs work
Issue tags: -views, -image attach, -multiple, -limit

Thanks rayasa. This is looking good.

Just a few points outlined below...

+++ image/contrib/image_attach/image_attach.module	2011-05-29 19:12:08.527951547 +0530
@@ -736,3 +736,18 @@ function image_attach_content_extra_fiel
+function image_attach_limits_validate($element, &$form_state) {

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?

+++ image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc	2011-05-29 19:11:34.187978802 +0530
@@ -83,7 +111,7 @@ class image_attach_views_handler_field_a
-          $values[$id]->image_attach_iids[$this->handler_key] = $attached_images[$v->{$this->aliases['image_attach_nid']}];
+          $values[$id]->image_attach_iids = array_slice($attached_images[$v->{$this->aliases['image_attach_nid']}], $display_limits['offset'], $display_limits['length']);

Wouldn't it be better to do this at the query level with an SQL LIMIT clause?

Powered by Dreditor.

rayasa’s picture

Thanks. 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.

mean0dspt’s picture

can we move on with this patch? looks like a good feature to me

alansch’s picture

Status: Needs work » Needs review

I'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.

joachim’s picture

Status: Needs review » Needs work

See my comments in #9 above.

joachim’s picture

Ok so image_attach_limits_validate() should be this instead:

  /**
   * Validate the options form.
   */
  function options_validate($form, &$form_state) { }

Also the spelling of 'Negetive' needs to be fixed ;)

joachim’s picture

Status: Needs work » Needs review
FileSize
3.91 KB

Insomnia 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.

johnlutz’s picture

Tried patch with 6.x-1.2 and am having problems. The new Display Limits aren't saving when I save the view.

joachim’s picture

Status: Needs review » Needs work

Views 2 or 3?

alansch’s picture

Version: 6.x-1.x-dev » 6.x-1.2
Status: Needs work » Needs review
FileSize
4.39 KB

I 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.

Status: Needs review » Needs work

The last submitted patch, 981078.patch.18.image_.image-attach-views-limit-images.patch, failed testing.

alansch’s picture

Another try at the patch

joachim’s picture

Status: Needs work » Needs review

Thanks!

Setting the status.

Let's see what the testbot says. If another user can then review the patch, I'll commit it.

Status: Needs review » Needs work

The last submitted patch, 981078.patch.20.image_.image-attach-views-limit-images.patch, failed testing.