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
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 1141374-file-should-be-object.patch | 1.11 KB | dave reid |
| #14 | 1141374-cast-thumbnails-as-objects.patch | 585 bytes | gollyg |
| #8 | 1141374-fix-some-files-not-thumbnails-media-browser.patch | 517 bytes | dave reid |
| #4 | media.theme_.inc_.patch | 722 bytes | Oleksandr.Masovets |
| #2 | media.theme_.inc_.patch | 849 bytes | Oleksandr.Masovets |
Comments
Comment #1
RavenHursT commentedI'm having a similar issue.. Not the same though.. http://drupal.org/node/1141536
Comment #2
Oleksandr.Masovets commentedHi guys.
Here is the patch, which will fix the error described above.
Comment #4
Oleksandr.Masovets commentedFixed patch
Comment #5
Oleksandr.Masovets commentedJust changing status
Comment #6
aaron commentedi don't get this error on 7.x-2.x. maybe this has been fixed since then?
Comment #7
rickvug commentedSubscribe.
Comment #8
dave reidI think this gets us at least a little better on track. Tested and works with a .pdf file in the library.
Comment #9
Leeteq commentedSubscribing.
Comment #10
waynedpj commentedsubscribe
Comment #11
phai commentedI'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).
Comment #12
damien tournoud commentedAFAIK, #8 is unnecessary, as
file_view_file()should do that already.The problem seems to be that
media_field_formatter_view()is adding#fileas 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?Comment #13
phai commentedThis 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)?
Comment #14
gollyg commentedIt 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.
Comment #15
Anonymous (not verified) commentedThis fixes the issue for me using Media: SoundCloud.
Comment #16
dave reidComment #17
dave reidAssigning for review.
Comment #18
dave reidI think this should resolve it once and for all.
Comment #19
dave reidTested 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
Comment #21
Lythimus commentedI 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.