Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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!
Thanks
Comment | File | Size | Author |
---|---|---|---|
#18 | entity-1481372-entity_uri_file-18.patch | 1.54 KB | skwashd |
#13 | entity-1481372-entity_uri_file.patch | 1.48 KB | skwashd |
#10 | 1481372-url_callback_for_file_entity.patch | 1.13 KB | ericras |
Comments
Comment #1
bluestarstudios CreditAttribution: bluestarstudios commentedUpdate: 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!
Comment #2
zincdesign CreditAttribution: zincdesign commentedsame here. I would like to know how make a link to specified PDFs when the node is displayed
Comment #3
dealancer CreditAttribution: dealancer commentedThe same happens for entities build with entity_api.
Comment #4
dealancer CreditAttribution: dealancer commentedI've noticed that referenced entity is not added to the node on load.
Comment #5
dealancer CreditAttribution: dealancer commentedFound a reason!
The referenced field values are unset from the entity in entityreference_field_formatter_prepare_view() before running the formatter.
If there is no access callback defined for the entities like file or some custom entities so the entity_access return NULL
Also see issue of entity api: http://drupal.org/node/981990
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedSo it seems to be an issue in Entity API. Let's move it there.
Comment #7
dealancer CreditAttribution: dealancer commentedThe weird thing is that entity_access() is called even for entities such as files, that does not use an entity api module.
Comment #8
dealancer CreditAttribution: dealancer commentedThe weird thing is that entity_access() is called even for entities such as files, that does not use an entity api module.
Comment #9
ericras CreditAttribution: ericras commentedI've had the same problem. See #1739834: Entity Reference field with Target Type: File does not display
Using
* 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.
Comment #10
ericras CreditAttribution: ericras commentedI 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.
Note:
Also see #1349640: The file entity should have an 'uri callback' defined in the File entity (fieldable files) project which tackled the same thing.
Comment #11
Courtney.B CreditAttribution: Courtney.B commentedApplied 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
Comment #12
XanoThe working code looks good.
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.
Comment #13
skwashd CreditAttribution: skwashd commentedRerolled with docs improvement.
Comment #14
ericras CreditAttribution: ericras commentedComment #15
fagoThis seems to be reasonable. I'm wondering whether that might conflict with file entity?
Comment #16
skwashd CreditAttribution: skwashd commentedI 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?Comment #17
fagoYes, let's do that to be safe.
Comment #18
skwashd CreditAttribution: skwashd commentedFinally got around to rerolling this based on @fago's feedback.
Comment #19
timaholt CreditAttribution: timaholt commentedTested this with File Entity 2.0-alpha2 and it works as advertised. Marking as RBTC.
Comment #20
fagoThanks, committed.