JavaScript errors with 'Add collection', 'Select media' (Media, Field Collection) I drupal 7 site that I did not build but now maintain has developed an odd error.  About a month ago the site lost the ability to add an image to a Media field inside a new addition of field collection.  Looking into it, this is what I find:


The first few warnings are nothing that I can see would harm things.  The media.popup.js error is nonsense: 

dialogOptions.buttons[ok] = function () {
  alert('hell yeah');
  return "poo";

  var formattedMedia = this.contentWindow.Drupal.media.formatForm.getFormattedMedia();
  if (!formattedMedia) {


I have yet to see that code be reached, though it looks a little unprofessional to have such things in a contrib module.

When I scroll down the node edit form I see see the next segment.  The Bulletin error has to do with Google Syndication code linked in, and can be ignored for now.

The piece of the screenshot after that is when I try to trigger the field collection's "Add Additional Item" button from the console.  Nothing happens.  I am not sure if I did it right, but I included it in this screenshot in case it helps identify anything.

The final segment shows the messages that appear when I click the Add Additional Item button.  A new field collection instance is actually added to the form, and if the console was not open I would not know that something was wrong yet.  I get from 2 to 5 instances of that "object is undefined" error any time I do this.  The "too much recursion" error occurs about 1 in 15 tries, so I do not know if it is relevant.  I have all cache and compression turned off, and this is a local virtual box copy of the live site so I do not have to worry about killing it in the investigation.  

The problem is these "object is undefined" errors block the use of the Media module's Select Media button for a field on the node.  First time this problem was noticed was when a new slide show entry was being added to an Article node.  The Add collection button causes the error, and the Media button then does not respond but throws some "this.hoverable" error.  I went over to another content type that has a field collection that contains only text, but also has a Media field on the node itself.  The field collection generates the same error, I switch vertical tabs to get to the Media field and it behaves the same as the media field inside the collection.  JQuery Update is used to keep the admin screens on jquery v1.5 because it is needed for the Media module.

Modules involved:


Drupal 7.38
Field collection (field_collection)  Module  Enabled      7.x-1.0-beta8
Chaos tools (ctools)  Module  Enabled     7.x-1.7
jQuery Update (jquery_update)   Module  Enabled     7.x-2.4 
Media (media)      Module  Enabled    7.x-1.5
OK, this was sort of entertaining.

The trail begins with this silliness in media.popups.js:

dialogOptions.buttons[ok] = function () {
  alert('hell yeah');
  return "poo";


Just as it stuck out for @DeveloperWeeks, it stuck out for me because I'm familiar with the work of Media module's primary maintainer, and I know him (by reputation) to be pretty meticulous. So in checking it out I discovered that it was removed long ago (like, in 2013) in this commit: Removed inappropriate JS code. 

(I am sure he would be thrilled, by the way, to know that this bit of code will now live forever after on StackExchange. :-P)

Since the OP lists as part of his installation the latest production release  of Media (7.x-1.5), this didn't mesh. The errors were originating from a two-year-old file.

With this compelling clue in hand, @DeveloperWeeks was able to locate an extra copy of the Media module hidden away in his installation. That's when the sun rose, the flowers bloomed, and things just generally started to make more sense. 

As for those pesky errors, well...


  "This is why "duplication of data" is such a horrible thing." -
  @DeveloperWeeks


Hell, yeah. ;-)