Closed (fixed)
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2012 at 13:01 UTC
Updated:
1 Dec 2016 at 20:34 UTC
Jump to comment: Most recent
Comments
Comment #1
johnpitcairn commentedThe hostEntity property looks to be protected. So $entity->hostEntity() won't work in some contexts. I think.
For example, I'm finding that I can use $entity->hostEntity() successfully on the entity in hook_entity_presave(), but not when I have manually loaded the entity somewhere else via entity_load(). Bah.
Comment #2
Bitvark commentedThe entity_load_single() function seems to work, for me.
Otherwise I think you can try with $entity->hostEntityId() and then loading the hosting entity with entity_load().
It happens sometimes that while hostEntity is unaccessible, hostEntityId is available.
Comment #3
kla2t commentedIn my template.php, I needed to pull content from the host node into a field collection field, and neither hostEntity() nor hostEntityId() were accessible to anonymous users.
As a workaround, I ended up with loading the node through menu_get_object() to get the required content.
This works, at least, for simple node pages. Might be useful for someone else since this problem seems to persist.
Comment #4
jmuzz commentedIt is normal. The host information isn't loaded by default when loading a field collection item. It will be loaded with a call to fetchHostDetails() which is called if necessary by any of the host information functions.
Hope this helps.