When reordering a gallery that has the multiple pages, the AJAX receives absolute deltas, but assumes they're relative. The offset is applied to the original deltas, resulting in the wrong file being put into the new delta. If the original delta for a file is in the last half of the gallery, that file in that slot can be removed from the node completely, as the original delta + offset will be out of bounds for the array. This also results in duplication of files in the Gallery.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MPetrovic created an issue. See original summary.

MPetrovic’s picture

Patch removes offset when getting the file in the old delta.

Moloc’s picture

Status: Active » Postponed (maintainer needs more info)

I am not able to reproduce this issue with your given details. The order is relative, not absolute, therefore the offset is needed.

Are you using a patched version of media_gallery?
Can you provide steps, how to reproduce this issue?

MPetrovic’s picture

FileSize
8.13 KB

We are using patches, but only one of them doesn't refer to an issue on Drupal.org. That patch disables the drag and drop behavior when not on the node page itself (for instance, if the gallery is in a block or something).

Here's the patch if you're curious:
https://raw.githubusercontent.com/openscholar/openscholar/b92cbafb00bdec...

This is what the body of the request to save the order looks like on my end:
Request body
It looks like it's just getting the ids, which are generated with "media-gallery-media-{absolute delta}", and then passing them to the server. Is this not how it's supposed to look?

Moloc’s picture

Your patch looks fine for me.

The posted data are absolute, you are right. But the should be relative (starting with 0, 1, 2,...)
This is done in media_gallery.module @ line ~414

    // Field rendering requires sequential deltas, so re-key.
    // @todo Open a Drupal core issue about this.
    if ($media) {
      $node->media_gallery_file[LANGUAGE_NONE] = array_values($media);
    }

I applied your patch locally and i am still not able to reproduce your issue.

Do you have the gallery multiple times on the page? Do you have multiple different galleries on the page?

ivnish’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)