Get / Prepare all the field collection's data

Public

Prepares the node's field collection data into an array, useful for templating purposes

Get raw version
php
  1. $fieldname = 'field_lorem_slides';
  2.  
  3. // Get the items
  4. $slides = array();
  5. foreach($vars[$fieldname] as $delta => $item_id){
  6. $data = field_collection_item_load($item_id['value']);
  7. if ($data)){
  8. $l = isset($data->language) ? $data->language : LANGUAGE_NONE;
  9. $slides[$delta] = array();
  10.  
  11. // Get the field collection's data prepared in an array
  12. // Alternatively, you could do $slides[$delta] = $data; in order to get the full objects in the array
  13. $slides[$delta]['lorem_image'] = '<img src="'.file_create_url($data->field_image[$l][0]['uri']).'">';
  14. $slides[$delta]['lorem_data'] = isset($data->field_heading[$l]) ? $data->field_heading[$l][0]['safe_value'] : null;
  15. }
  16. }
  17.  
  18. // Send the information to the template file
  19. // $vars['slides'] = $slides;