I am using Entity Reference all over my Drupal 7.12 website. If I'm referencing content everything works perfectly fine. If however I want to reference a file the result is empty. I can reference it, and it saves, however regardless of how I choose to display the file (Label, Rendered...) nothing appears. Your help on this issue would be greatly appreciated!

#18 entity-1481372-entity_uri_file-18.patch1.54 KBskwashd
PASSED: [[SimpleTest]]: [MySQL] 409 pass(es).
[ View ]
#13 entity-1481372-entity_uri_file.patch1.48 KBskwashd
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]
#10 1481372-url_callback_for_file_entity.patch1.13 KBericras
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]


Component:Code» User interface
Priority:Major» Critical

Update: I've noticed that if I reference a Content everything works. But referencing a File results in nothing. I can reference it, but once viewed it doesn't display. Under Manage Displays for the content type, regardless of the render format selected nothing gets displayed. Additionally I've noticed that if I select "Rendered Entity" and click the button on the right to configure it, it doesn't load anything.
Please help!

same here. I would like to know how make a link to specified PDFs when the node is displayed

The same happens for entities build with entity_api.

I've noticed that referenced entity is not added to the node on load.

Found a reason!

The referenced field values are unset from the entity in entityreference_field_formatter_prepare_view() before running the formatter.

// Check whether the referenced entity could be loaded and that the user has access to it.
if (isset($target_entities[$item['target_id']]) && entity_access('view', $field['settings']['target_type'], $target_entities[$item['target_id']])) {
// Replace the instance value with the term data.
$items[$id][$delta]['entity'] = $target_entities[$item['target_id']];
// Otherwise, unset the instance value, since the entity does not exists or should not be accessible.
else {
$rekey = TRUE;

If there is no access callback defined for the entities like file or some custom entities so the entity_access return NULL

function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
  if ((
$info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
$info[$entity_type]['access callback']($op, $entity, $account, $entity_type);

Also see issue of entity api: http://drupal.org/node/981990

Title:Using Entity Reference to Reference Files results in nothing displayedentity_access('file', $file) returns FALSE
Project:Entity reference» Entity API
Version:7.x-1.0-beta5» 7.x-1.x-dev
Component:User interface» Core integration
Priority:Critical» Normal

So it seems to be an issue in Entity API. Let's move it there.

The weird thing is that entity_access() is called even for entities such as files, that does not use an entity api module.

The weird thing is that entity_access() is called even for entities such as files, that does not use an entity api module.

I've had the same problem. See #1739834: Entity Reference field with Target Type: File does not display

* Entity API 7.x-1.0-rc3+10-dev (2012-Sep-06)
* Entity Reference 7.x-1.0-rc5

I am now able to get the file Entity Reference field to display on my page. However it is not linked, it is just the plain text file name.

So I'm assuming entity_access('file', $file) no longer returns false. It is now not rendering the link.

Title:entity_access('file', $file) returns FALSEFile entity should have an 'uri callback' defined
Status:Active» Needs review
new1.13 KB
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]

I think the "entity_access('file', $file) returns FALSE" problem outlined above was solved by #1136356: Fix file access

As I mentioned in #9 above, I now get the file name to render with Format=Label and 'Link to the Referenced Entity' on the field's Manage Display tab.

However, since the file entity does not define a 'uri callback', entity_uri() returns null and the file name is plain text with no link.

Also see #1349640: The file entity should have an 'uri callback' defined in the File entity (fieldable files) project which tackled the same thing.

Applied patch in #10 - in my initial test, I found that it did fix the problem of Files not linking.

I'm out for the rest of the day, but I'll be keeping track if I encounter other errors tomorrow and let you know.

Thanks for your work! It just eased my work life a bit. :)

Entity API - Sep 6, 2012 Dev version
Entity Reference - 1.0-rc5 version

Status:Needs review» Needs work

The working code looks good.

+++ b/modules/callbacks.inc
@@ -946,3 +946,13 @@ function entity_metadata_field_query($entity_type, $property, $value, $limit) {
+ * Callback so that entity_uri() can generate a uri for file entities.

Use something like "Implements hook_entity_info() URI callback" to make clear what kind of callback this is exactly, and also so the parameters and return value do not have to be documented explicitly. If the code comment is fixed, I'll mark this RTBC.

Status:Needs work» Needs review
new1.48 KB
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]

Rerolled with docs improvement.

Status:Needs review» Reviewed & tested by the community

This seems to be reasonable. I'm wondering whether that might conflict with file entity?

I tested this patch on a site using file entity 7.x-1.x before submitting it. There wasn't a conflict.

I've just checked 7.x-2.x and it implements a uri callback generates "file/[fid]" URIs for files. I suppose we could wrap logic in if(empty($entity_info['file']['uri callback'])). Do we care about file entity 2, which is current at unstable7?

Status:Reviewed & tested by the community» Needs work

Yes, let's do that to be safe.

Status:Needs work» Needs review
new1.54 KB
PASSED: [[SimpleTest]]: [MySQL] 409 pass(es).
[ View ]

Finally got around to rerolling this based on @fago's feedback.

Status:Needs review» Reviewed & tested by the community

Tested this with File Entity 2.0-alpha2 and it works as advertised. Marking as RBTC.

Status:Reviewed & tested by the community» Fixed

Thanks, committed.

Status:Fixed» Closed (fixed)

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