Unlike hook_field_attach_*()
prepare/view hooks, hook_field_*()
prepare/view hooks have no access to the requested language, they just get the actual language to be used for the current field. In the case of an untranslatable field, this prevents to implement a localized formatter, e.g. a date formatted with the current locale settings.
Comment | File | Size | Author |
---|---|---|---|
#11 | tf-1178500-11.patch | 10.87 KB | plach |
#10 | tf-1178500-10.patch | 12.1 KB | plach |
#9 | tf-1178500-1.patch | 11.63 KB | Damien Tournoud |
#6 | tf-1178500-1.patch | 11.63 KB | Damien Tournoud |
#1 | tf-1178500-1.patch | 11.63 KB | plach |
Comments
Comment #1
plachThe attached patch adds the parameter
$request_language
to thehook_field_attach_*()
prepare/view hooks.Comment #3
plachComment #4
sun#1: tf-1178500-1.patch queued for re-testing.
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedRe-uploading the same patch.
Another use case: a localized taxonomy term referenced by a untranslatable taxonomy term reference field.
Comment #8
plach@DamZ
This is a more valid use case: in mine we should be using the current interface language instead of the requested content language. I'll update the PHP docs accordingly once the bot has reviewed the patch.
Comment #9
Damien Tournoud CreditAttribution: Damien Tournoud commentedNew try.
Comment #10
plachReplaced the example in the PHP docs with the use case from #6.
Comment #11
plachRemoved a couple of unnecessary changes.
Comment #13
plach#11: tf-1178500-11.patch queued for re-testing.
No failures on my box.
Comment #14
Damien Tournoud CreditAttribution: Damien Tournoud commentedIssue summary
When rendering a field, the Field API calls
field_language()
to select the best language to render the field based on both (1) the requested rendering language, (2) the languages the field is defined in. The field is then rendered, but the requested rendering language is not passed to the field formatter.As a consequence, there is no way for the formatter to take the correct decision when rendering sub-objects. For example: if you have a "taxonomy term reference" field attached to a node, you might want this field not to be translatable (because the terms are always the same in every language) but you still want to render the terms in the display language of the node.
API changes
This patch is fully backward compatible.
It introduces small API addition by adding a new
$requested_language
parameter to a bunch of hooks.Why is this patch important
It allows building proper formatters, thus unlocking more of the i18n niceties of Drupal 7 :)
Comment #15
plachObviously this should be backported to D7.
Comment #16
webchickSame question as the other issue; if this is fixing a bug, we ought to be able to test it, right?
(It's fine to push back on this, btw. I just get nervous when there's this much code flinging around and no safety net. We ended up introducing notices into 7.2 for a similar thing.)
Comment #17
webchickComment #18
plachWell, I did not add tests exactly because, as in the other issue you mentioned, I thought it was overkill.
Let me just note that IMO my mistake in #1089174: Prepare view hooks do not receive the language parameter has been not to split the issue into one fixing the bug and another one adding the extra language parameter. Notices arose from the former, the latter was totally harmless as this one should be.
That said, I'll try to provide tests, but I guess this is a D7.4 issue now...
Comment #19
ytsurkany news ?
can i help in a way ?
here a clear test case is offering: #1121722: Improve DX of instance translation
Comment #20
muschpusch CreditAttribution: muschpusch commentedsubscribing. When it's backported to D7 i'm willing to test it!
Comment #21
andypostShould we close this issue? language parameter been removed in #1089174: Prepare view hooks do not receive the language parameter
I think the formatter should know language to pass it to sub-objects. Another example a node back reference field which renders referred nodes - probably this case could be solved on load stage, seems the same for taxonomy reference field
Comment #22
valthebaldI second #21