3

I have a node in Dutch and I want to get the field in this language. When I do:

$node->field_name[$node->language][0]['value'];

I get the error:

Undefined index: nl

So I try:

$node->field_name[$node->language]['nl']['value'];

But that doesn't work. What am I doing wrong?

Edit:

I already figured it out:

$language = field_language('node', $node, 'field_yourfield');

This gave me the language of the field and it was 'und' and not 'nl' as I thought it would be. The language of the node can be different then of the field. Learnt a lot about i18 & Drupal :)

1
  • 1
    if you found a solution, please post it as an answer to your question and mark it as accepted (after the 24 hr waiting period) instead of putting it in the question
    – Laxman13
    Aug 31, 2011 at 19:45

1 Answer 1

1

I use a function from this blog post to retrieve the fields value, it's quite handy as it allows you to parse the different values of the field (also it handles value or nid).
Drupal 7 tip : Get field values from entity objects like nodes, users, taxonomy...

Regarding the und, I'm not very sure why is this happening, I saw this issue: Field display languages are cached before locale has changed field language, but I have to wrap my head against this.

4
  • und means there's no language set, in most cases the language is set on the node, not on the fields, so all fields have 'und' as language
    – Attiks
    Aug 31, 2011 at 22:05
  • And is it normal to have und on field while the node has a language ? I haven't seen the option to configure individual language for the fields. Do you have some links to clarify this for me ? Thanks.
    – tostinni
    Sep 1, 2011 at 0:45
  • 1
    yes, it's normal. Unless you define the language of the field it will always be und, check Gabor's blog, a must read for i18n.
    – Attiks
    Sep 1, 2011 at 19:15
  • Ok so, with core only field are und, if I put a module like Entity translation then I can have some fr fields instead of und. Thanks for the tip.
    – tostinni
    Sep 1, 2011 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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