This was noted as an aside within the undefined index issue but I want to make sure it was called out specifically so it's easy to find and noted to either fix or list as a dependency in some way so it doesn't continue to trip people up.

The problem: If your site does not have Clean URLs enabled, adding media to a gallery via the "Add media" button, or any of the other AJAX related functionality will not work since the URLs used in the AJAX queries will not resolve and result in a 404 error.

Members fund testing for the Drupal project. Drupal Association Learn more


Womp’s picture

Version: 7.x-1.0-beta2 » 7.x-1.0-beta4
Priority: Minor » Normal

This is a bit more than a 'minor' issue in my opinion. If you do not have clean URLs, media is not properly attached to the gallery node that you save it to (media_gallery.addimage.js). If that first issue is fixed, all ordering of media in the display does not save if moved around (media_gallery.dragdrop.js).

The current code in media_gallery.addimage.js that doesn't work for me is:

var src = Drupal.settings.basePath + 'media-gallery/add-images/' + Drupal.settings.mediaGalleryNid + '/' + Drupal.settings.mediaGalleryToken;

This fix worked for me and should work for those with clean URLs as well (let me know what you think because I never touch JavaScript compared to PHP). I replaced the code above with:

var browserUrl =;
var not_clean_url = /\?q=/;
var src = not_clean_url.test(browserUrl) ? (Drupal.settings.basePath + '?q=media-gallery/add-images/' + Drupal.settings.mediaGalleryNid + '/' + Drupal.settings.mediaGalleryToken) : (Drupal.settings.basePath + 'media-gallery/add-images/' + Drupal.settings.mediaGalleryNid + '/' + Drupal.settings.mediaGalleryToken);

If my code is appropriate, I could add a variation to media_gallery.dragdrop.js as well.


tamasd’s picture

Version: 7.x-1.0-beta4 » 7.x-1.0-beta6
Status: Active » Needs work
1 KB

I have rolled a patch against the latest beta and it works for me. Could you add the media_gallery.dragdrop.js support to the patch?

David_Rothstein’s picture

Thanks for the patch.

I haven't tested and only reviewed quickly, but i think the normal way to deal with this kind of thing is actually to define the URL entirely on the PHP side of the code (in which case the Drupal url() function can be used which takes care of clean URLs and everything automatically for you).

Then add that variable as a JavaScript setting using drupal_add_js(), and access it on the JavaScript side via Drupal.settings.addImageUrl (or whatever the variable was called).

Would that approach work here?

temaruk’s picture

Version: 7.x-1.0-beta6 » 7.x-1.x-dev
Status: Needs work » Needs review
1.03 KB

Patch against latest dev, fixes the issue in PHP side using Drupal's url() function, and passing it as a js setting ( Drupal.settings.addImageUrl ). Only for media_gallery.addimage.js.

David_Rothstein’s picture

Status: Needs review » Fixed

Thanks! I added code to fix media_gallery.dragdrop.js in a similar way (and also to remove some of the extra JavaScript settings that were no longer needed after this patch) and committed it:

The Media Gallery module should now work even on servers that don't support clean URLs.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.