The following code renders images from a multiple value field collection associated with a node via entity reference. This code does work, but as you can see, I am using LANGUAGE_NONE. Most of what I read recommends using field_get_items() so that the language is properly determined but I haven't been able to get this to work with my code. I believe this may be due to the entity reference or the use of entity_metadata_wrapper() as the field I'm trying to get is another level deeper because it belongs to the field_collection.

Could someone provide some guidance as to the correct to handle this?

      // the nid_1 field is the gallery id which is supplied by a view using an entity reference
      $gal = entity_metadata_wrapper('node', $post['nid_1']);
      // field_gallery_images is the field_collection and contains image and caption fields
      $gal_imgs = $gal->field_gallery_images->value();

      $o = '';
      // this loops through all the image fields in the field_collection, renders them and adds them to the output var
      foreach ($gal_imgs as $key => $img) {
        $o .= theme('image_style', array('path' => $img->field_image[LANGUAGE_NONE][0]['uri'], 'alt' => '', 'style_name' => 'gallery-small'));
      }

Comments

jmuzz’s picture

Issue summary: View changes
Status: Active » Fixed

You should be able to use field_get_items. The entity type will be field_collection_item . It looks like the entity will be $img and the field name will be field_image.

Hope this helps.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.