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

sun’s picture

No idea, subscribing.

yched’s picture

Hm, 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 ?

David_Rothstein’s picture

Subscribing.

Carlos Miranda Levy’s picture

subscribe - getting error

yareckon’s picture

Carlos Miranda Levy’s picture

Yep, that fixed it :-)
Thanks.

avpaderno’s picture

Status: Active » Closed (duplicate)
Related issues: +#1089174: Prepare view hooks do not receive the language parameter