With #2121253: Attach media browser JavaScript settings and #2316707: Drupal.settings.media values become an array of when multiple fields are used the media browser settings were "simplified" and moved to a library which makes the media_attach_browser_js() and media_browser_js() helper functions unnecessary, since they require more code and the loading of a file, compared to simply #attaching the library.

Ex:

module_load_include('inc', 'media', 'includes/media.browser');
$javascript = media_browser_js();

foreach ($javascript as $key => $definitions) {
  foreach ($definitions as $definition) {
    $element['#attached'][$key][] = $definition;
  }
}

vs.

$element['#attached']['library'][] = array('media', 'media_browser');
$element['#attached']['library'][] = array('media', 'media_browser_settings');

The media_browser library should probably depend on the settings library anyway, which would remove the second line as well.

Comments

devin carlson’s picture

Status: Active » Needs review
StatusFileSize
new2.81 KB

A patch to remove the functions.

devin carlson’s picture

Status: Needs review » Fixed

Tested #1 and committed to Media 7.x-2.x.

  • Devin Carlson committed b88290c on 7.x-2.x
    Issue #2454933 by Devin Carlson: Removed JS helper functions.
    
steel-track’s picture

Just a heads up that this causes a function undefined error with the CKeditor module's plugin loading:

ckeditor/includes/ckeditor.lib.inc line 893

if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media')) {
      module_load_include('inc', 'media', 'includes/media.browser');
      $javascript = media_browser_js();
      foreach ($javascript as $key => $definitions) {
        foreach ($definitions as $definition) {
          $function = 'drupal_add_' . $key;
          call_user_func_array($function, $definition);
        }
      }
      drupal_add_js(drupal_get_path('module', 'ckeditor') . '/plugins/media/library.js', array('scope' => 'footer', 'weight' => -20));
    }
  }

Are they aware of this change?

pol’s picture

StatusFileSize
new1 KB

Here's the patch.

And the line for you, makefile lovers:

projects[ckeditor][patch][] = https://www.drupal.org/files/issues/Issue_2454933.patch

pol’s picture

steel-track’s picture

@Pol - Thanks for the patch!

lunk rat’s picture

Patch in #5 solves this for me. I just upgraded from media 1.x to 2.x-dev and ckeditor was giving

Fatal error: Call to undefined function media_browser_js() in ckeditor/includes/ckeditor.lib.inc on line 893

So when #1 makes it into a full release, will you submit #5 to be committed to ckeditor module?

izmeez’s picture

This patch in #5 applies to ckeditor and has been filed in it's own issue #2455391: Call to undefined function media_browser_js() latest Media-7.x-2.x-dev
Further discussion should be there.

Status: Fixed » Closed (fixed)

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

ddease2’s picture

#25 worked for me