It is not possible to save some of the values of the language field with entity metadata wrapper, because it throws a validation error.
It affects all the languages that contains a "-"
For example: pt-br
Error message:
Invalid data value given. Be sure it matches the required data type and format. Value at user(1)->field_lang: pt-br. dans EntityMetadataWrapper->set()

The definition of the field is the following:
'property_type' => 'token'

It is the value that entity metadata wrapper takes into account when validating, and with this "token" value the usage of "-" is not allowed.

CommentFileSizeAuthor
#5 2895585-data-type.patch413 bytesstephaneq

Comments

mr.york created an issue. See original summary.

johnv’s picture

Can you give me an example how to test this?

stephaneq’s picture

Hi,

I have the same issue, but only with some languages. I'm still investigating, but I found the field has the "token" type, and according to the documentation (https://www.drupal.org/docs/7/api/entity-api/data-types), it can accept only "A string containing only lowercase letters, numbers, and underscores; e.g. this type is useful for machine readable names."

So my guess is the error occurs when the language has also the country code in its name (for example, fr-be, pt-br etc.), as the dash is not accepted.

johnv’s picture

Op also states that Token is the root cause. Can you change it to 'text' and test that?

stephaneq’s picture

StatusFileSize
new413 bytes

I tested, and it works.
I made a patch, but I don't know the other impacts that it may have to change the data type.

stephaneq’s picture

Status: Active » Needs review
johnv’s picture

Title: Invalid data value given. Be sure it matches the required data type and format. Value at user(1)->field_lang: pt-br. dans EntityMetadataWrapper->set() » Not all language codes are accepted

  • johnv committed 38a40b9 on 7.x-1.x authored by StephaneQ
    Issue #2895585 by StephaneQ: Not all language codes are accepted
    
johnv’s picture

Version: 7.x-1.x-dev » 7.x-1.6
Status: Needs review » Fixed

Thanks,
committed as-is.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

czigor’s picture