I had to add a patch to reset the weights after an image is deleted.

Otherwise the weights skip a number for the deleted image and when a new image is uploaded, sometimes it doesn't come up at the end.

CommentFileSizeAuthor
image_attach_delete_weight.patch775 bytesppatriotis

Comments

joachim’s picture

Ah right, you mean if we delete an image node that happens to be attached somewhere else?
Yup, that makes sense.

An alternative approach would be to allow weight to be non-sequential, and deal with the possibility that our weights are like [1, 5, 8], say.

There was a bit of discussion about this in the original issue #81102: Attach Multiple Images with image_attach using Drupal upload mechanism, but I don't think it was explicitly decided whether it's really a weight or a delta -- we've called it weight but seem to be normalizing it like a delta.

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure that this fixes the problem.

Bear in mind that the weight of attached images is pretty much arbitrary so far, in the absence of a UI.

Here's what I tried:

1. Create a story node, attach 4 existing images to it. In the DB these get weights 0-3.
2. Delete the image node that has weight 2.
3. The DB now has weights 0,1,3.
4. Do one of:
4A. Attach a new image by upload: it gets weight 3, and the existing ones become 0,1,2.
4B. Attach a new existing image. It gets weight 0, and the existing ones becomes 1,2,3. In this case, the new image was listed first in the selection box; this is what determines the eventual weight.

sun’s picture

Status: Postponed (maintainer needs more info) » Active

This sounds like you were able to replicate the bug, and we just don't know how to properly solve the problem.

joachim’s picture

Rather, it looks like the originally reported bug isn't a problem, but a newly uploaded image doesn't come up in the right place (perhaps even without the gap in the weights).

joachim’s picture

Status: Active » Closed (works as designed)

Actually, I'm going to close this.

> 4A. Attach a new image by upload: it gets weight 3, and the existing ones become 0,1,2.

The new image gets put at the end. That seems reasonable to me.

> 4B. Attach a new existing image. It gets weight 0, and the existing ones becomes 1,2,3.

Existing images get saved with weights reflecting the order in the selection box.

So this all works as designed -- though granted the design is pretty basic :/

There's a feature request elsewhere for a UI to reorder attached images.