After upgrading Drupal core and modules, it was noticed that on a settings page for a custom module, the file-upload button no longer worked. Clicking on the 'Add file' button resulted in a brief 'AJAX activity' icon and nothing else.

The file-upload field was created through the Forms API, using

  $form["headerblock"]["headerblock_image_fid"]=array(
    '#type' => 'media',
    '#title' => t('Image').' (75x90 pixels)',
    '#default_value' => variable_get("headerblock_image_fid"),
    '#media_options' => array(
       'global' => array(
         'types' => array('image')
       )
    )
  );

Pre-upgrade this same code generated a field with an 'Browse' button that opened the MediaBrowser popup, allowing one to select an image from the library or upload a new file.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Marco Vervoort created an issue. See original summary.

Marco Vervoort’s picture

Comparing the pre- and post-upgrade versions of the media-module, I found that the problem was with the 'initMediaBrowser()' function in the file sites/all/modules/contrib/media/js/media.js. This function is passed a CSS selector referring to form-field. Pre-upgrade this function assumed the browse-button to be a child of the element, post-upgrade this function assumed the browse-button to be a sibling.

As the site in question had no unusual settings which could affect the HTML-code generated for the upload-widgets, this problem is likely to affect other sties as well. On any site, the upload-field is unlikely to have browse-buttons that are siblings or children of the upload-field and not related to the upload-field. As such, the 'initmediaBrowser()' function can be made more robust by modifying it to search for both siblings and children.

I have attached a patch which achieves this.

pontus_nilsson’s picture

Status: Active » Needs review

I also had this problem after upgrading. With the patch from #2 I got this working.

Status: Needs review » Needs work

The last submitted patch, 2: media-2795927-1.patch, failed testing.

joseph.olstad’s picture

Patch needs reroll

scottalan’s picture

Re-rolling the patch.

This also fixed an issue with the media browser when loaded using the Panelizer in-place-editor.

scottalan’s picture

Status: Needs work » Needs review

  • scottalan authored 2cc0161 on 7.x-3.x
    Issue #2795927 by Marco Vervoort, scottalan: Media-browser popup does...

  • scottalan authored 2cc0161 on 7.x-2.x
    Issue #2795927 by Marco Vervoort, scottalan: Media-browser popup does...
joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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