I have a form with a wysiwyg media integration and a multi field file with the media widget.
When I upload more than 2 files in my field file, I can't upload an image in the wysiwyg. The popup freeze with the message : "The file image_2MB.jpg was uploaded".

I use CKeditor with the wysiwyg module.

Do you know what is the problem ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cedric’s picture

Version: 7.x-1.1 » 7.x-1.2
FileSize
1.05 KB

The bug is also present on 7.x-1.2

The javascript error was:

Uncaught TypeError: Object /media/-media_id-/format-form?render=media-popup,/media/-media_id-/format-form?render=media-popup,/media/-media_id-/format-form?render=media-popup,/media/-media_id-/format-form?render=media-popup has no method 'replace'

Attached patch handles the cases where defaults.src is an array of strings and seems to fix the issue. Can someone with more knowledge of the code review this?

cedric’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, media-1630288-1.patch, failed testing.

cedric’s picture

FileSize
1.03 KB

proper patch

cedric’s picture

Status: Needs work » Needs review
stefgosselin’s picture

Status: Needs review » Reviewed & tested by the community

Amazing! Patch in #4 made my day. Tested and approved.

stefgosselin’s picture

aaron’s picture

I noticed that this code also still exists in V 7.X-2.x. Could someone please let us know if the bugs still exists in that version? If so, then we will need to fix it there first, and then back port.

ParisLiakos’s picture

Version: 7.x-1.2 » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs work
+++ b/js/media.popups.jsundefined
@@ -150,8 +150,18 @@ Drupal.media.popups.mediaBrowser.finalizeSelection = function () {
+    defaults.src = defaults.src.replace('-media_id-', mediaFile.fid);  ¶
...
+  ¶
...
+  ¶

patch also contains 3 white spaces

ParisLiakos’s picture

brunodbo’s picture

Similar issue in 7.x-2-x yes. I came across it when using media with Panels (see #1901516: Inserting media in WYSIWYG textarea while using Panels, which is marked as duplicate of this):

* Add a custom panel pane to a panel page.
* Click the 'Add media' button in the WYSIWYG editor.
* Upload a file or find one in the library.
* Click submit.

Clicking submit should take you the file edit form (when uploading a new file) or the file style form (when choosing one from the library) in the modal, but it doesn't in this case.

After applying the patch in #4, when uploading a new file, the file edit form is loaded, but when I click 'Save', I'm getting the message that 'File <file_name> was updated, in an otherwise empty modal, and the modal is frozen, with no way to close it.

After applying the patch in #4, when choosing a file from the library and clicking 'Submit', nothing happens.

In both cases, the console shows:

Uncaught TypeError: Object /media/-media_id-/format-form?render=media-popup,/media/-media_id-/format-form?render=media-popup has no method 'replace' (program):155
Drupal.media.popups.mediaStyleSelector (program):155
InsertMedia.onSelect (program):163
s jquery.js:36
dialogOptions.buttons.(anonymous function) (program):84
Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad (program):108
c.event.handle jquery.js:64
h.handle.o jquery.js:57
gmclelland’s picture

@brunodbo - I couldn't seem to reproduce the error. Without any patching everything seemed to work when I tried it. Can this be reproduced on a fresh install?

brunodbo’s picture

Just tested it on a fresh install of everything, and indeed, all seems good. #11 is invalid, sorry for the noise.

designar’s picture

I've experienced the same issue on the latest media module in a panopoly installation.
The patch from #4 helped to fix the problem.

John Pitcairn’s picture

I am experiencing this issue in 7.x-2.0-unstable7 or 7.x-2.0-dev.

I have media-image fields contained in a multivalue field collection, and media-wysiwyg integration on the node body field. The Wysiwyg popup uses a cloned and customized Views display. If I add more than one field collection item containing an image, wysiwyg image selection from the popup fails with the javascript error:

media.popups.js:152 - TypeError: 'undefined' is not a function (evaluating 'defaults.src.replace('-media_id-', mediaFile.fid)')

The patch at #4 applies (with whitespace errors) to latest dev or 7.x-2.0-unstable7 and prevents the error.

But I am finding that the first item inserted from the popup is "sticky", ie if you go back and attempt to insert another item elsewhere in the text, you can select a different item and submit at step 1, but at the next step (choose format), the first-inserted item is displayed, and submitting inserts that.

The last item in the defaults.src array still contains the fid from the previous insert, so the replace on "-media_id-" does not find anything to replace.

John Pitcairn’s picture

FileSize
1.01 KB

This updated patch adds a regex search for either possibility and removes the whitespace errors. I thought it prudent to check for the slashes either side of the relevant path argument rather than just a run of numbers (fid).

John Pitcairn’s picture

Status: Needs work » Needs review
MiroslavBanov’s picture

Status: Needs review » Needs work

The last patch #16 doesn't work for me.
I am getting a 404 with this URL "/media/-media_id-/format-form?render=media-popup,/media/297/format-form?render=media-popup"
Maybe this is the Array case, but I am only inserting one image, so I don't know why this happens.

I am using ckeditor module (not wysiwyg) and fieldable_panel_panes module.
On first look, patch #4 works for me, and I am redirected to "/media/298/format-form?render=media-popup"

GoZ’s picture

Status: Needs work » Needs review
FileSize
1.38 KB

Patch doesn't work for me either.

problem comes from defaults.src[defaults.src.length-1], my array hasn't a key integer but the value string as key.

So this is a patch which work for me (and make sure to return string)

This patch is part of the #1day1patch initiative.

aaron’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me.

ndobromirov’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.04 KB

I used the patch in #19 in single field CKEditor. The patch works some predefined number of times and then starts to generate: "call to missing method replace on undefined" errors in the browser's console.

After some digging, the issue is that the 'shift' method removes the value from the defaults, and inevitably at some point the array goes empty, resulting in the issue described.

Adding a patch, based on the one in #19, but after the shift method, returns the value back with unshift, this prevents the array from getting empty.

ndobromirov’s picture

Re-rolled the patch against revision 8798bfcd24501959fc024e9b7a9b52fec98fc1d8.

ianthomas_uk’s picture

#21 fixes the problem for me in 7.x-2.0-alpha2

ianthomas_uk’s picture

Issue summary: View changes

environnement

lanzs’s picture

using media 7.x-2.0-alpha3 and #21 doesn`t helped, still get this error in console: ~format-form?render=media-popup&fields=undefined
Any other ideas how to fix it?

dagomar’s picture

This is a patch against revision 2283c03, I need this NOW!

WMarkus’s picture

I have a similar problem. Uploading an image freezes the GUI (Browser). The image is uploaded to the server, but it never appears in any gallery. Someting is plain wrong here.

mike.davis’s picture

Status: Needs review » Reviewed & tested by the community

I was having the same issues when using ECK fields. #21 sorted it out for me on 7.x-2.0-alpha3.

aaron’s picture

aaron’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
webatelier’s picture

Still experiencing this in media 1.4 and panels => add custom content into a page
I'm having exactly the same issues as in #11 with following JS error

Uncaught TypeError: Object [object Array] has no method 'replace'

hefox’s picture

The version of this needs to change to 1.x since commited to 2.x, right?

  • aaron committed cdd67b4 on 7.x-3.x
    Issue #1630288 by ndobromirov, GoZ, John Pitcairn, dagomar: Upload image...
joseph.olstad’s picture

Status: Patch (to be ported) » Fixed

This was fixed by @aaron a while back, RIP good fellow!

Status: Fixed » Closed (fixed)

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