[support] Accessing values in the $node variable..

Nancy Wichmann nan_wich at bellsouth.net
Tue May 28 12:59:49 UTC 2013


Here's some code I use for dealing with collections. Perhaps it will help you to solve you problem.
  $collection = field_get_items($entity_type, $entity, 'field_consultant_cost_breakout');
  $count = count($collection);

  $total = 0;
  for ($i = 0; $i < $count; ++$i) {
    // Entity_load will return an array with the entity number as the key.
    $item = array_pop(entity_load('field_collection_item', array($entity->field_consultant_cost_breakout[LANGUAGE_NONE][$i]['value'])));
    $total += $item->field_total_cost[LANGUAGE_NONE][0]['value'];
  }


 
Nancy 

Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.



>________________________________
> From: Wipe_Out <wipe_out at users.sourceforge.net>
>To: support at drupal.org 
>Sent: Tuesday, May 28, 2013 6:05 AM
>Subject: [support] Accessing values in the $node variable..
> 
>
>
>Probably a simple syntax question but as a non-programmer I am battling with it..
>
>
>I have created an "Invoice" content type that uses an entity reference to a "Patient" content type and within that there is a field collection for addresses.. I am trying to get the address in the first item in the field collection..
>
>
>My guess is that I have to use something like "entity_load" which I will have to work out when I get there but at the moment I can't work out the syntax for accessing the field collection ID so I can try and load the data for the field collection..
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130528/559665ac/attachment.html 


More information about the support mailing list