When the "Generic file" display is used, viewing a File Entity results in a blank icon without a filename and the following error message are displayed:
Notice: Trying to get property of non-object in theme_file_link() (line 701 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in theme_file_icon() (line 739 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_path() (line 781 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_map() (line 823 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_path() (line 796 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_path() (line 796 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_path() (line 796 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in file_icon_path() (line 796 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in theme_file_link() (line 708 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in theme_file_link() (line 708 of /[...]/modules/file/file.module).
Notice: Trying to get property of non-object in theme_file_link() (line 714 of /[...]/modules/file/file.module).
The root of the issue is in file_build_content
, right after calling file_view_file()
, it unset the #file
property of its result. But the default file field formatter returns a render array using the file_link
theme hook. This theme hook requires a file</file> variable, which in a render array translates to the the <code>#file
property. So when the actual rendering of the array happens, theme('file_link')
is called without the required file
variable, resulting in the reported error messages.
Comment | File | Size | Author |
---|---|---|---|
#8 | file_entity-n1270036-8.patch | 776 bytes | DamienMcKenna |
#7 | file_entity_check_theme_index_set.patch | 761 bytes | yareckon |
#1 | file_build_content_breaks_file_field_defaut_formatter-1270036-1.patch | 1.01 KB | pbuyle |
Comments
Comment #1
pbuyle CreditAttribution: pbuyle commentedHere is a simple patch that avoid unsetting
$file->content['file']['#file']
if it uses thefile_link
theme hook.Comment #2
rickvug CreditAttribution: rickvug commentedI can reproduce this problem by visiting a URL such as media/2. Applying the patch fixes the problem. Based on the description of the problem the small code change makes sense so marking RTBC.
Comment #3
andypanix CreditAttribution: andypanix commentedSame problem me too. I can confirm that applying the patch fixes it.
Comment #4
amateescu CreditAttribution: amateescu commentedI've been hit by this while working on #1201936: Move the media field to a non-required submodule. Tested the patch and I second the RTBC status.
Comment #5
Dave ReidI'm dubious about this, but I guess we need it. Committed to 7.x-1.x.
http://drupalcode.org/project/file_entity.git/commit/63cfb6c
Comment #6
shaman365 CreditAttribution: shaman365 commentedHeads up,
I am actually receiving this error with this patch:
Notice: Undefined index: #theme in file_build_content() (line 198 ....sites/all/modules/file_entity/file_entity.file_api.inc)
However, when I roll back the patch, I don't see any errors. I'm using the "URL to file" display style and my media field is being displayed in a view.
Comment #7
yareckon CreditAttribution: yareckon commentedYeah we need to check if that index is set before reading it. Attached patch does so.
Comment #8
DamienMcKennaSlightly improved formatting of the if() statement.
Comment #9
DamienMcKennaThe patch from #7 fixed the problem for me, I just cleaned up the changed line a little bit with my patch in #8. Can I RTBC the patch or should someone else do it?
Comment #10
Dave ReidCommitted #7 to Git. Thanks for the follow-up everyone.
http://drupalcode.org/project/file_entity.git/commit/c1ab850
Comment #11
Lukas von Blarerthank you!