I have a computed field in a Drupal 7 content type that is populated by my description (text) field:
$entity_field[0]['value'] = $entity->field_desciption['und'][0]['value'];
It works fine. I want to create another computed field that is populated by the title (Node module element) field.
I tried with the following lines, but they don't work.
$entity_field[0]['value'] = $entity->title['und'][0]['value'];
$entity_field[0]['value'] = $node->title;
How can I achieve this?
Best Answer
The node title is not a field; therefore, using
$entity->title['und'][0]['value']
will not work. What you should use is$entity->title
.As side note, to get the value of a field, you should use field_get_items(), which takes care of the language set for the field, which isn't necessarily
LANGUAGE_NONE
.