Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
the entity wrapper always write to LANGUAGE_NONE if no certain language is given. However the current behaviour in core is different, see core issue #1208856: Enabling locale module changes field default language.
Defaulting to the language as returned from field_valid_language() should fix it.
Comment | File | Size | Author |
---|---|---|---|
#9 | entity_set_lang.patch | 1.51 KB | fago |
#7 | 1208862-7.patch | 965 bytes | derhasi |
Comments
Comment #1
fagorules issue #1204886: Updating field values fails if the locale module is enabled
Comment #2
fagofrom discussion with plach in IRC I think we need an entity_language() to fix this. Also I guess the wrapper's language() method should default to that language, not language none.
Comment #3
plachComment #4
fagoalso see the rules issue #1204886: Updating field values fails if the locale module is enabled
Comment #5
fagoadding tag
Comment #6
derhasi CreditAttribution: derhasi commentedI found out of a similar problem, when using auto_nodetitle. There tokens are not provided for node creation, but for node updates.
As I recognized this occurs because in entity_metadata_field_property_get() the $langcode is retrieved as 'und', but the node form provided its fields as (in my case) 'de' (for German).
So I have an entity with
but the due to the $langcode it wants to look for 'und'.
Btw. $options['language'] is set to NULL, as $this->getPropertyLanguage() returns NULL, in EntityStructureWrapper::getPropertyValue(), where entity_metadata_field_property_get() is called.
Comment #7
derhasi CreditAttribution: derhasi commentedBy further investigation, I guess I fell into a core bug that leeds to some wrong field language associations: #1238042: Field display languages are cached before locale has changed field language.. i recognized that after testing to patch the entity wrapper with some defaultLanguage behaviour.
The patch for that is attached here.
Looking into core, the only entity to providing a language property seems to be 'node'. I guess simply looking for $data->language would not fit to other entity approaches, but therefore I'm not enough into the entity api, to provide a more generic patch. Hope this patch might help anyway.
Comment #8
plachRelated issue: #1260640: Improve field language API DX.
Comment #9
fagoLooks like, we are going to need that entity_language() stuff to be able to fix this. Once this is settled in core we can think about improving the wrappers.
For now, we could just use $entity->language if it's there. See patch attached.
Comment #10
fagook, I've committed this as interim workaround until an entity_language() function arrives in core.