Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | media-2795927-6.patch | 1.03 KB | scottalan |
| |||
#2 | media-2795927-1.patch | 1005 bytes | Marco Vervoort |
Comments
Comment #2
Marco Vervoort CreditAttribution: Marco Vervoort commentedComparing 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.
Comment #3
pontus_nilssonI also had this problem after upgrading. With the patch from #2 I got this working.
Comment #5
joseph.olstadPatch needs reroll
Comment #6
scottalan CreditAttribution: scottalan at Phase2 commentedRe-rolling the patch.
This also fixed an issue with the media browser when loaded using the Panelizer in-place-editor.
Comment #7
scottalan CreditAttribution: scottalan at Phase2 commentedComment #10
joseph.olstad