Spin off from #526122: Autocomplete widget for taxonomy term fields:
On entity preview (currently comments and nodes have previews), the values handed out by widgets are transformed into field values passed to field_attach_view().
Since widgets are supposed to massage their data into ready-for-storage format, the values coming from preview 'look' like regular values loaded from storage, with the difference that they didn't go through hook_field_load() and hook_field_attach_load().
This is annoying, because hook_field_load() is used to load additional information about the values (e.g for 'taxo term' field type, load term name from the tid).
Then each formatter needs to handle the case where hook_field_load() hasn't run and thus load the data it needs itself.
Attached patch makes sure values coming from preview run through hook_field_load() and hook_field_attach_load().
It relies on the presence of an $object->in_preview boolean flag. There's no legacy discrepancies here like those we had to handle for 'id key' or 'bundle key', both node and comment set this flag on their previews, so we are allowed to write this flag name in stone and not bother with exposing an 'in_preview key' in hook_fieldable_info().
Comment | File | Size | Author |
---|---|---|---|
#12 | 549710_11_field_preview.patch | 2.23 KB | scor |
#11 | 549710_11_field_preview-D8.patch | 2.23 KB | scor |
#11 | 549710_11_field_preview-D7.patch | 2.19 KB | scor |
#5 | field_preview-549710-5.patch | 1.94 KB | yched |
#3 | field_preview-549710-1.patch | 1.93 KB | yched |
Comments
Comment #1
yched CreditAttribution: yched commentedHeh, that copy/paste was a little naive...
Better patch.
Comment #3
yched CreditAttribution: yched commentedGrr, I uploaded the same patch twice. That one should work.
Comment #5
yched CreditAttribution: yched commentedgosh.
Comment #6
bjaspan CreditAttribution: bjaspan commentedI do not understand why you are using FIELD_LOAD_REVISION:
If that is correct, it needs a comment to explain it to me. :-)
Comment #7
yched CreditAttribution: yched commentedYeah, the thing is we don't have any information here to determine the correct value for $age, so using FIELD_LOAD_REVISION, which is the 'most generic' case.
I'll add a comment when I'm where I can reroll.
As a side note: I'm note sure the $age param is actually useful for hook_field_load() and hook_field_attach_load(). Note that we already don't reflect the $options param from field_attach_load().
Comment #9
catchThis is a bug, not a task. #493314: Add multiple hook for formatters deals with a similar area.
Comment #10
raj47i CreditAttribution: raj47i commented#1: field_preview.patch queued for re-testing.
Comment #11
scor CreditAttribution: scor commentedMarking #1061212: image_field_formatter fails in comment preview as duplicate, and retitling this issue to highlight the bug it fixes in the comment preview. To reproduce, add a file or image field to comment, and preview a new comment or an existing comment.
I'm attaching a reroll of #5 which solves the comment issue. I've also added the removal of _field_invoke_multiple() in node_preview() since this is now handled in field_attach_view() directly.
Comment #12
scor CreditAttribution: scor commentedah, so -D8.patch is not recognized?
Comment #14
scor CreditAttribution: scor commentedforgot to bump version.
Comment #15
scor CreditAttribution: scor commented#12: 549710_11_field_preview.patch queued for re-testing.
Comment #16
scor CreditAttribution: scor commentedPasting the notices this patch fixes so people experiencing these errors can find this issue... These notices happen when previewing file and image fields on comments.
Comment #17
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedthis patch seemed to work
http://drupal.org/node/1443158#comment-6231824
Comment #28
catchThere's no longer field rendering separate from entity rendering, so closing this as outdated.