media_include_browser_js() is called by several functions both in media and media gallery module. Looking through it looks like all of those are while building renderable arrays, which means it could likely be changed to media_attach_browser_js(&$element) to add the library and javascript via #attached instead.

Comments

catch’s picture

Status: Active » Needs review
StatusFileSize
new2.01 KB

Added the new function and tested with the 'add media' link from media_gallery().

This doesn't yet replace media_include_browser_js() since wyswiyg's hook_INCLUDE_plugin() doesn't appear to allow more than one js file, or libraries. Not really sure what to do about that yet.

catch’s picture

Double checked and wysiwyg definitely doesn't allow more than one js file or support libraries at the moment. Will think about a patch to wysiwyg, but don't want to introduce a dependency on that here so this may be the best we can do for now.

catch’s picture

StatusFileSize
new4.07 KB

Slight update, won't be able to test this until tomorrow. Adds a helper for the js definitions, moves the wysiwyg-specific stuff out of there into media.inc. This at least removes the code duplication, all still not very nice.

catch’s picture

StatusFileSize
new4.07 KB

module_load_include() arguments always catch me out...

catch’s picture

StatusFileSize
new4.18 KB

Updated patch, I've now tested this with both the media gallery block and wysiwyg + ckeditor, all appears to be working fine.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed this patch and the code looks fine to me. I didn't actually test it out, but since @catch did I think it's fine.

The use of call_user_func_array() looks fragile to me (probably won't work with certain combinations that can theoretically be passed in as #attached?) but that's a reflection of the Drupal APIs for adding JS/attached being kind of a mess, and given that it's just a workaround for the WYSIWYG issue it seems fine for now. Expanded code comments around that point might not be a terrible idea, though.

catch’s picture

StatusFileSize
new4.46 KB

I updated that code comment, and also added an @see for the wysiwyg issue to media_media_plugin(). Since these are only comment changes, leaving at RTBC.

JacobSingh’s picture

This looks good to me, I'm going to try and test and commit tomorrow.

JacobSingh’s picture

Status: Reviewed & tested by the community » Fixed

I agree w/ David about the call_user_func being brittle, but I also agree that it isn't likely to become an issue ever, so it's mostly academic.

Committed. Nice work :)

KeesMK’s picture

Status: Fixed » Needs review

It seems after this patch is processed uploading files is not possible anymore.

See also:
http://drupal.org/node/1067298
and
http://drupal.org/node/1067248

Please look into this. Seems to be solved bij changing a little code within the media_gallery.module.

catch’s picture

Status: Needs review » Closed (duplicate)

This seems to have been fixed on #1067248: Fatal error after updating Media module.

David_Rothstein’s picture

Status: Closed (duplicate) » Closed (fixed)
twod’s picture

I've created a new issue to deal with this in a way which acually works like '#attached', but it requires a change in Wysiwyg that would greatly benefit from your review. See #1795968: Prepare for wysiwyg_load_includes being cached for the overview.