Hi All,

I don't know whether this is the right place to ask or should it be in view_php module issue queue. Let me just place in two places.
Normally, I can retrieve a field value under View PHP (http://drupal.org/project/views_php) through $data. But for the special field of type field collection. I don't know how to retrieve its items.

Say I have a field_collection in content type A
There are two fields under this field_collection called
field_item1
field_item2

How can I retrieve field_item1 and field_item2 value in the View PHP in order to do some further processing?
Thanks

Comments

truyenle’s picture

Didn't mean to bump it up, but I can't figure out how. Anyone?

truyenle’s picture

I got it finally, here is the code
collection field: field_banner_videos
collection items:
field_video_url
field_custom_thumbnail

$field_collection_array_object = $data->field_field_banner_videos[0]['rendered']['entity']['field_collection_item'];// field collection array
reset($field_collection_array_object); // Move pointer to the beginning of the array
$item_id = key($field_collection_array_object); // get the item_id in the collection
$field_collection_item = entity_load('field_collection_item', array($item_id));
foreach ($field_collection_item as $item)
{
   $video_id = $item->field_video_url['und'][0]['query']['v'];// get video id
   $custom_thumbnail = $item->field_custom_thumbnail['und'][0];
}

// Further processing the collection item values go here...

Thanks

RedJane’s picture

Version: 7.x-1.0-beta4 » 7.x-1.0-beta5

Pfew... :-/
Tried already a lot... but still no luck.
Is there another solution for this? Thank you !
(Using beta5)

RedJane’s picture

ok... finaly found it using field_collection_item_load()
Me Happy.

nasia123’s picture

It would be nice to display your solution also with field_collection_item_load()