hello
i am new to drupal , i wanted to created a computed field based on some values and one of them was a term reference .
i used expression like this :
$entity_field[0]['value'] = $entity->field_vendor[LANGUAGE_NONE][0]['value']
and it gave me unknown index 'value'.
i tried 'name' instead and it worked :
$entity_field[0]['value'] = $entity->field_vendor[LANGUAGE_NONE][0]['name']
i'd like to know , am i doing this right ?
p.s. i have locale enabled :)

Comments

abrebion’s picture

None of this work for me. Any idea how I can access the value of a taxonomy field ?

mohscorpion’s picture

have you used print_r function for debugging values ?
i found my problem using that very sweet function...
for example set the computer field to output of print_r function like this :
$entity_field[0]['value'] = print_r($entity);
or like this :
$entity_field[0]['value'] = print_r($entity->field_vendor);
when you found the language you are looking for , then go to in more details like this :
$entity_field[0]['value'] = print_r($entity->field_vendor[LANGUAGE_NONE]);
and more details :
$entity_field[0]['value'] = print_r($entity->field_vendor[LANGUAGE_NONE][0]);
this way you can debug what is going on there...

zualas’s picture

I am assuming that you wanted to get the term name based on a term reference. The system saves only the term ID in the entity object, so in order to get the term name, I am using (replace field_test_taxonomy with your field name):
$entity_field[0]['value'] = taxonomy_term_title(taxonomy_term_load($entity->field_test_taxonomy['und'][0]['tid']));

abrebion’s picture

that works perfectly, thank you very much !

colan’s picture

Category: task » support
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

cimo75’s picture

How can i get other fields? i am doing

$term=taxonomy_term_load($node->taxonomy_vocabulary_6['und'][1]['tid']);
$result=field_view_field('taxonomy_term',$term,'field_mytermfield');
$entity_field[0]['value'] = $result

but it does not work.
tx
Simone