I'm trying to manually update a node and I'm not sure how the language works.

The node is in English, so $node->language = 'en';

However, all my fields data are organized like this in the node:


I thought 'und' means "language undefined", so shouldn't it be 'en' instead?

I'm trying to automate the process so is it safe to assume fields will always use 'und' in nodes?


Yes - it is safe to assume this. The locale module will deal with this by setting it to the language code of the default language, ex 'en'.

Citing from: http://drupal.org/update/modules/6/7#drupal_language_none

In Drupal 7, the LANGUAGE_NONE constant should be used for nodes or other items that do not have a specific language associated with it.


You can get field values without use LANGUAGE_NONE.

$field_items = field_get_items('node', $node, 'field_name');
$value = $field_items[0]['value'];

Instead of specifying a language, I prefer to just use entity_metadata_wrapper().

For example:

$node = entity_metadata_wrapper('node', SOME_NODE_ID);
$value = $node->field_something->value(); // returns field value
$node->field_something->set('new value'); // sets field value

Source: https://www.drupal.org/docs/7/api/entity-api/entity-metadata-wrappers

  • Hey hey, welcome to DA. Nice snippet. But I don't actually see how this answers OP's problem? – leymannx Jun 14 '18 at 21:40
  • It's more of a different way to solve the root problem so that the actual question becomes a moot point. – Garrett W. Jun 14 '18 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.