Reading field collection item

Public

Read field collection item value and prepare better variable for template files.

Get raw version
php
  1. // Prepare better variables for template file.
  2. $better_vars = array();
  3. foreach ($variables['elements']['field_ow_discover']['#items'] as $key => $item) {
  4. $entity_id = $item['value'];
  5. $entity = field_collection_item_load($entity_id);
  6. $wrapper = entity_metadata_wrapper('field_collection_item', $entity);
  7.  
  8. $better_vars[] = array(
  9. 'title' => $wrapper->title_field->value(),
  10. 'content' => $wrapper->field_basic_text_text->value(),
  11. );
  12. $variables['columntext'] = $better_vars;