I only just noticed this; file names are displaying for image files and internet video files, but any other file type (we have mostly PDFs) are not displaying the file name in any media browser view. I noticed it when trying to select media from the Media Library, and found that the same thing was happening for the basic media browser view at admin/content/media as well.

https://skitch.com/idlewilder/fx5u3/media-library-other-files
https://skitch.com/idlewilder/fx5sw/content-media-thumbnail-display

Comments

phenaproxima’s picture

I was having this exact same problem. After some searching through the code, I found the problem (and the solution)!

Check out modules/media/includes/media.theme.inc, line 309:

function template_preprocess_media_thumbnail(&$variables) {
  // Set the name for the thumbnail to be the filename.  This is done here so
  // that other modules can hijack the name displayed if it should not be the
  // filename.
  $variables['element']['#name'] = isset($variables['element']['#file']->filename) ? $variables['element']['#file']->filename : NULL;
}

The problem is that $variables['element']['#file'] might not be an object, which causes $variables['element']['#name'] to be NULL, rather than the filename. Change the function to look like this, and the problem goes away :)

function template_preprocess_media_thumbnail(&$variables) {
  // Set the name for the thumbnail to be the filename.  This is done here so
  // that other modules can hijack the name displayed if it should not be the
  // filename.
  $file = (object)$variables['element']['#file'];
  $variables['element']['#name'] = isset($file->filename) ? $file->filename : NULL;
}
phai’s picture

Really thanks... I hope it will be included in the new release.

phai’s picture

StatusFileSize
new9.1 KB

Mmm... I don't know why... but it was necessary to add the following line
$element['#file'] = (object)$element['#file'];
to avoid a similar warning at 286.
I put it at 278:
$element = $variables['element'];
$element['#file'] = (object)$element['#file'];

I attach the new version of the file (with both the modifications) renaming it .txt.

arthurf’s picture

Status: Active » Closed (duplicate)

The same issue (and similar fix) is posted here: http://drupal.org/node/1141374

I'm not seeing this issue on 1.x or 2.x anymore (and I'm unclear why $variables['element']['#file'] would be an array in the first place) so perhaps updating to latest dev or 2.x will fix this.

I'm closing this as a dupe but if the issue is not fixed, please post on the other issue.