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

Wipe_Out wipe_out at users.sourceforge.net
Tue May 28 13:29:25 UTC 2013


Thanks.. I will look into those options and see if I can get there..


On 28 May 2013 14:14, Lucas D Hedding <lucashedding at gmail.com> wrote:

> If don't mind trying something new, I'd recommend using
> entity_metadata_wrapper from the entity API.
>
> Here's a specific example<http://www.appnovation.com/part_2_entity_metadata_wrappers_and_entity_api>using field collections and a more general
> example <https://drupal.org/node/1021556>. I've found
> entity_metadata_wrapper to be much easier than dealing with $node->
> field_foo[LANGUAGE_NONE][0]['value'] all over the place. Place a
> dependency on entity in your .info file and have fun.
>
>
> Lucas
> MTech, LLC <http://www.mtechinformationsolutions.com>
>
>
> On Tue, May 28, 2013 at 7:59 AM, Nancy Wichmann <nan_wich at bellsouth.net>wrote:
>
>> 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..
>>
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130528/15124414/attachment.html 


More information about the support mailing list