Currently, when setting the wrapper's language to LANGUAGE_NONE and fetching a translatable field's value, if the field has value in language-none but doesn't have one in the default language, the empty default language value will be returned.
It happens, for instance, when the content was created before Locale was enabled.

I suggest the attached fix for this case.

Files: 
CommentFileSizeAuthor
#13 entity-translatable_fields_not_overriding_und_with_empty_values-1782134-13.patch836 byteshelmo
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]
#12 commerce_message_patch_error.jpg108.3 KBgc11
#5 entity-translatable_fields_not_overriding_und_with_empty_values-1782134-5.patch837 bytesDevin Carlson
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]
entity-translatable_fields_not_overriding_und_with_empty_values.patch932 bytesitamar
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]

Comments

amitaibu’s picture

willieseabrook’s picture

Status:Needs review» Reviewed & tested by the community

I am using commerce backoffice from commerce kickstart, and was having the problem that message text was not being showed.

I applied this against entity-7.x-1.0-rc3 and now it works fine.

Thanks for the patch!

itamar’s picture

fago’s picture

Status:Reviewed & tested by the community» Needs work

It happens, for instance, when the content was created before Locale was enabled.

In that case it's the job of the entity's translation handler to care about moving all the values. It's ugly yep, but this is what core does already. Check the locale translation handler of nodes.

I'd be happy to add whatever utility function to the entity API such that is easy to implement for entity-providing modules.

Devin Carlson’s picture

StatusFileSize
new837 bytes
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]

An update of the original patch which fixes an issue where the langcode was being set to LANGUAGE_NONE even if the field has a value under the default language.

m.schwarzenberg’s picture

Patch fixes also this issue on OpenAtrium 'Can't see nodetitles in recent activity'(after Module Locale is enabled).
https://drupal.org/node/2036413

Thank you.

petr-oa’s picture

Same problem after enable Locale module.
Patch #5 helped.
Thank you!

klausi’s picture

+++ b/modules/callbacks.inc
@@ -529,6 +529,12 @@ function entity_metadata_field_get_language($entity_type, $entity, $field, $lang
+      if (empty($entity->{$field['field_name']}[$langcode]) && !empty($entity->{$field['field_name']}[LANGUAGE_NONE])) {

empty() is certainly wrong here, since the string "0" is also empty(), but a legit value. isset() would be more appropriate.

isellakuria’s picture

Patch #5 worked for me, it solved the issue pointed out here: https://drupal.org/node/1932530

Mariem001’s picture

Issue summary:View changes

#5 it works! thx

manuelBS’s picture

Patch at #5 also works for me.

gc11’s picture

StatusFileSize
new108.3 KB

As it's semi related to this I have opened up a topic on Commerce Message (https://drupal.org/node/2220849) as #2 had problems with backoffice. I had to update Entity to the latest dev for another module install, re applied the patch, albeit in a slightly different section but then unfortunately it results in errors in some of the messages.

I've attached the screenshot in case anyone else is having the same issue.

thx

helmo’s picture

Status:Needs work» Needs review
StatusFileSize
new836 bytes
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]

Here's an updated patch with @klausi's remark from #8

It fixed #2146311: E-mail notifications are empty for me.

sinasalek’s picture

Status:Needs review» Reviewed & tested by the community

I've had a problem with messages module not showing message contents on non english pages and applying #13 patch fixed the problem.

manuelBS’s picture

For the same, that patch fixed my problem with the messages module, too.

fago’s picture

Status:Reviewed & tested by the community» Closed (won't fix)

I'm still not convinced #13 is right - there might be no values in the original language on purpose - so just ignoring that seems wrong. That said, this really seems to be a won't fix issue to me. If you disagree, I'd love to hear plach's thoughts on this before adding a fallback like this. But to my best knowledge, this should be a won't fix.

I know message module does some trickery with the content language, so if there are rendering problems with that it might make sense to look into improving how it stores it values instead.