4
votes

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?

3

3 Answers

2
votes

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.

1
votes

If it's a node module element, it should be accessible via $entity->title directly. Try a print_r($entity); die; to get all elements of the entity. Hope this help you.

0
votes

You should look at printing the array/object to the page to see what you are working with exactly.

Try adding print_r($entity); or print_r($node); to the page where the entity or node is displayed followed by exit;

You can then right click the page and click 'View page source' to display the output in a structured format. Use this to see the variable names, object/array types and hierachy to then write your full variable code correctly.

print_r($node);
exit;

I would imagine it should have been $node->title though...