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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pbuyle’s picture

Here is a simple patch that avoid unsetting $file->content['file']['#file'] if it uses the file_link theme hook.

rickvug’s picture

Status: Active » Reviewed & tested by the community

I 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.

andypanix’s picture

Same problem me too. I can confirm that applying the patch fixes it.

amateescu’s picture

I'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.

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

I'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

shaman365’s picture

Heads 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.

yareckon’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Fixed » Needs review
FileSize
761 bytes

Yeah we need to check if that index is set before reading it. Attached patch does so.

DamienMcKenna’s picture

FileSize
776 bytes

Slightly improved formatting of the if() statement.

DamienMcKenna’s picture

The 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?

Dave Reid’s picture

Status: Needs review » Fixed

Committed #7 to Git. Thanks for the follow-up everyone.
http://drupalcode.org/project/file_entity.git/commit/c1ab850

Lukas von Blarer’s picture

thank you!

Status: Fixed » Closed (fixed)

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