diff --git a/field_collection.module b/field_collection.module index 3a8f9e9..63f329a 100644 --- a/field_collection.module +++ b/field_collection.module @@ -606,6 +606,44 @@ class FieldCollectionItemEntity extends Entity { } /** + * Ensure file fields on the entity have their URIs loaded for previews. + */ + public function view($view_mode = 'full', $langcode = NULL, $page = NULL) { + global $language_content; + + // If possible, get the content language from the environment if it wasn't + // provided. + if ($langcode == NULL) { + if (isset($language_content) && isset($language_content->language)) { + $langcode = $language_content->language; + } + else { + $langcode = LANGUAGE_NONE; + } + } + + // Iterate over file fields in the collection & merge file info into fields. + $field_instances = field_info_instances($this->entityType, $this->field_name); + foreach ($field_instances as $field_name => $field) { + $info = field_info_field($field_name); + if (in_array($info['type'], array('image', 'file')) && $file_field = &$this->$field_name) { + $file_langcode = isset($file_field[$langcode]) ? $langcode : LANGUAGE_NONE; + // Merge all of the loaded file in to the field to be passed to relevant + // theme function. + if (isset($file_field[$file_langcode])) { + foreach ($file_field[$file_langcode] as &$field_to_be_updated) { + if (!isset($field_to_be_updated['uri'])) { + $file = file_load($field_to_be_updated['fid']); + $field_to_be_updated += (array) $file; + } + } + } + } + } + return entity_get_controller($this->entityType)->view(array($this), $view_mode, $langcode, $page); + } + + /** * Export the field collection item. * * Since field collection entities are not directly exportable (i.e., do not