I get the following errors when I am viewing the thumbnail listing of media that contains a non-image piece of media on the current 7.x-1.x branch (with the file_entity changes)

Notice: Trying to get property of non-object in template_preprocess_media_thumbnail() (line 313 of /acquia/d7/sites/all/modules/media/includes/media.theme.inc).
Notice: Trying to get property of non-object in theme_media_thumbnail() (line 286 of /acquia/d7/sites/all/modules/media/includes/media.theme.inc).

Here is a screenshot of the error http://screencast.com/t/tyJePWO7

Comments

RavenHursT’s picture

I'm having a similar issue.. Not the same though.. http://drupal.org/node/1141536

Oleksandr.Masovets’s picture

Status: Active » Needs review
StatusFileSize
new849 bytes

Hi guys.

Here is the patch, which will fix the error described above.

Status: Needs review » Needs work

The last submitted patch, media.theme_.inc_.patch, failed testing.

Oleksandr.Masovets’s picture

StatusFileSize
new722 bytes

Fixed patch

Oleksandr.Masovets’s picture

Status: Needs work » Needs review

Just changing status

aaron’s picture

i don't get this error on 7.x-2.x. maybe this has been fixed since then?

rickvug’s picture

Subscribe.

dave reid’s picture

I think this gets us at least a little better on track. Tested and works with a .pdf file in the library.

Leeteq’s picture

Subscribing.

waynedpj’s picture

subscribe

phai’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc1

I'm coming from http://drupal.org/node/1252490

I get again the same error using this new version also:
« Notice: Trying to get property of non-object in theme_media_thumbnail() (line 286 di /.../sites/all/modules/media/includes/media.theme.inc). »

In the error box one line for each "other" kind file appears.
I'm going to modify the above file again (with the previous changes I hope).

damien tournoud’s picture

AFAIK, #8 is unnecessary, as file_view_file() should do that already.

The problem seems to be that media_field_formatter_view() is adding #file as the content of $item, which is an array. Changing this fixes the problem, but I'm not sure what exactly needs fixing as this whole code is supposed to be deprecated... why is it called anyway?

  // @todo Legacy support for the extra formatter added to file fields. See
  //   media_field_formatter_info().
  if ($display['type'] == 'media_large_icon') {
    foreach ($items as $delta => $item) {
      $element[$delta] = array(
        '#theme' => 'media_formatter_large_icon',
        '#file' => $item,
      );
    }
    return $element;
  }
phai’s picture

Version: 7.x-1.0-rc1 » 7.x-1.0-rc2

This time I have to edit:

theme_media_thumbnail($variables): ad at row 280
// Fix http://drupal.org/node/1141374
$element['#file'] = (object)$element['#file'];

function template_preprocess_media_thumbnail(&$variables): just rewrite the function in this way:
// Fix http://drupal.org/node/1141374
$element = $variables['element'];
$element['#file'] = (object)$element['#file'];
$variables['element']['#name'] = isset($element['#file']->filename) ? $element['#file']->filename : NULL;

To answer to arthurf message in the post I'm coming from:
"...and I'm unclear why $variables['element']['#file'] would be an array in the first place..."
I don't know, but I can ensure you that it is an array in my page.
Can it depend from another module integration (es: media_youtube, media_browser_plus) or a theme (my theme is made by Artisteer)?

gollyg’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
StatusFileSize
new585 bytes

It may be to do with the file object being cast as an array in file_entity_file_formatter_file_field_view().

The notes say:
Set $items to what file field formatters expect. See file_field_load()

So I think that ensuring that the file is cast as an object as in #13 is probably the easiest way to be sure that it doesn't throw the error, but not sure if it is the best way.

Have attached a patch to implement that.

Anonymous’s picture

This fixes the issue for me using Media: SoundCloud.

dave reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Issue tags: +D7 stable release blocker, +needs backport to 1.x
dave reid’s picture

Assigned: Unassigned » dave reid

Assigning for review.

dave reid’s picture

StatusFileSize
new1.11 KB

I think this should resolve it once and for all.

dave reid’s picture

Status: Needs review » Fixed

Tested and confirmed. Committing #18 to 7.x-2.x and 7.x-1.x. Thanks everyone!
http://drupalcode.org/project/media.git/commit/b764d29
http://drupalcode.org/project/media.git/commit/775a93f

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

Lythimus’s picture

Issue summary: View changes

I was getting a similar error which caused my thumbnails not to render when I accidentally uninstalled Responsive Image after selecting it as an image style for things in d8. Reinstalling/enabling it did the trick.