This is a problem in 7.x-1.0-beta5 and from a quick look at the code, appears to still be in 7.x-2.x-dev.

In media browser, going from 'Library' tab to another tab and back again results in the error in "Undefined index: file in media_browser_list()". This may occur under other circumstances as well when query in media_browser_list() (in media.browser.inc) returns empty. Offending code is (around line 175-9):

  $result = $query->execute();
  $files = file_load_multiple(array_keys($result['file']));
  foreach ($files as $file) {
    media_browser_build_media_item($file);
  }

  drupal_json_output(array('media' => array_values($files)));

I suggest checking for empty result first:

  $result = $query->execute();

  $media = '';
  if (!empty($result)) {
    $files = file_load_multiple(array_keys($result['file']));
    foreach ($files as $file) {
      media_browser_build_media_item($file);
    }
    $media = array_values($files);
  }
  
  drupal_json_output(array('media' => $media));

Comments

dazweeja’s picture

Actually this might be better (don't json encode if not necessary):

$result = $query->execute();

if (!empty($result)) {
  $files = file_load_multiple(array_keys($result['file']));
  foreach ($files as $file) {
    media_browser_build_media_item($file);
  }
  $media_files = array('media' => array_values($files));
  drupal_json_output($media_files);
  exit();
}
dddave’s picture

Status: Active » Closed (cannot reproduce)

This seems to be fixed by now. At least I am not able to reproduce it...