The first line of node_view_multiple() is field_attach_prepare_view() and the first hook that invokes is hook_field_prepare_view() for the field type module only.
As I understand it, hook_field_prepare_view() is where entity reference modules (e.g., nodereference.module) are supposed to load the entities being referenced. I'm not quite sure why taxonomy.module loads its taxonomy terms in taxonomy_field_formatter_prepare_view instead of in taxonomy_field_prepare_view(), because it seems to me that in general, it would make sense for entity reference fields to load the referenced entities in hook_field_prepare_view(), rather than requiring every formatter to have to do that.
Anyway, the problem comes in when you want to implement pagination. For example, suppose that you have a node with a multi-valued nodereference field containing 1000 items, and you want to format this is a paged list of teasers. If the nodereference module implements the node loading in hook_field_prepare_view(), how can you make it so that only the items that will be displayed on the current page get loaded?
I think we need something like a hook_field_attach_before_prepare_view() or hook_field_formatter_before_prepare_view() or perhaps both. Such a hook could then unset() stuff in $items prior to it reaching hook_field_prepare_view().
Thoughts?
Comments
Comment #1
sunNo idea, subscribing.
Comment #2
yched commentedHm, that's why loading the entities is rather a job for the formatter's prepare_view() ? - like taxonomy field currently does, and noderef field in CCK HEAD does as well.
Not all formatters need a fully loaded object - noderef default formatter only needs node titles.
If a formatter wants to do paging, then it's best to have it handle loading the objects it needs ?
Comment #3
David_Rothstein commentedSubscribing.
Comment #5
Carlos Miranda Levy commentedsubscribe - getting error
Comment #6
yareckon commentedCarlos, your problem is probably here #1089174: Prepare view hooks do not receive the language parameter
Comment #7
yareckon commented#1169426-7: Field invoke multiple does not handle field language correctly and here
Comment #8
Carlos Miranda Levy commentedYep, that fixed it :-)
Thanks.
Comment #9
avpaderno