Background
Calling node_preview()
does not involve using the active language of the node at hand. Rather, through calling node_view()
with no $langcode
parameter set, it results in falling back to using the global content_language
. For example, when a user clicks the 'Preview' button when editing a translation, in a system that does not have URL detection enabled, or when editing a translation of a node in a disabled language, the preview of the translated content comes in the content language, which is not always what is expected.
Workaround
Inside entity_translation_field_language_alter()
, check whether the entity at hand is a node with the in_preview
property set to TRUE. If this is the case, use the node's active language when calling locale_field_language_fallback()
.
Comment | File | Size | Author |
---|---|---|---|
#4 | entity_translation-node_preview-2876265-4.patch | 3.85 KB | stefanos.petrakis@gmail.com |
| |||
#2 | entity_translation-node_preview-2.patch | 2.94 KB | stefanos.petrakis@gmail.com |
|
Comments
Comment #2
stefanos.petrakis@gmail.comAnd here is a patch (with tests).
Comment #3
plachNice solution, almost good to go!
Bear with me, but I'd have one request: can we move this code to
entity_translation.node.inc
? I'm trying to keep all entity_type-specific code confined there (see for instance http://cgit.drupalcode.org/entity_translation/tree/entity_translation.mo...).Previews ;)
Missing @param types
I'd use
assertIdentical
/assertNotIdentical
here, to avoid unexpected failures should the body be moved to the very beginning of the string (very unlikely ;)Comment #4
stefanos.petrakis@gmail.comRerolling (against dev).
Regarding 1.: I pass two extra arguments to the entity-specific field language alteration functions, the $entity and the $handler, thought this would make for more economic code-writing.