2

I have written this code inside a computed field, which has given me as result, the referenced entity numbers how are saved in the field as an array.

I would like to know how to extract from the entity number a specific field, such as the title.

foreach ($entity->field_campos as $field) {
} 
foreach ($field as $index => $valores) {
$terminos[] = $valores['value'];
}
$item2 = field_collection_item_load_multiple($terminos, $reset = FALSE);
foreach ($item2 as $indice => $values) {
$entity_field[]['value'] = $values->field_nombre_2['und'][0]['target_id'];
}

// Display code (PHP).
$display_output = $entity_field_item['value'];

I am using Drupal 7.

0

1 Answer 1

2

You can do something like this:

$referenced_titles = array(); 

foreach ($item2 as $indice => $values) {

  // use node_load($nid) to load the node. 
  $referenced_node = node_load($values->field_nombre_2['und'][0]['target_id']);
  $referenced_titles[] = $referenced_node->title;

}
0

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.