Unfortunately, your self-answer is not so universal. Field language and node language are not the same things.
Field language is needed only if you are using Field Translation API (for example Entity translation). When you start using it, some fields are converted to translatable.
Translatable fields have language code, which really makes sense. But if the field is not translatable, the language code will always be (and for all content types, entities, etc) — LANGUAGE_NONE
(best to use the constant LANGUAGE_NONE
and not the string 'und'
).
So with your solution you can get a situation when a node is Russian, but a field of the node uses LANGUAGE_NONE
.
Happily, fields are attached to the form with '#language'
key, which always contains the correct language code.
$lang = $form['FIELDNAME']['#language'];
$form['FIELDNAME'][$lang][0]['value']['#value'] = $value;
If you have no access to attached form, Field Language API functions can be useful.
foreach
loop. If it's just LANGUAGE_NONE, that's a single run. In form_alter sense, it should technically alter whatever the language the form has.