From 2ce87a8ee6f968b8a5d7d7422d9789d2fb7bbd5e Mon Sep 17 00:00:00 2001 From: Colan Schwartz Date: Wed, 12 Mar 2014 13:39:37 -0400 Subject: [PATCH] Issue #1447338 by colinafoley, colan | quasi: Fetch collection images when previewing. --- field_collection.module | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/field_collection.module b/field_collection.module index 6462014..6149a9b 100644 --- a/field_collection.module +++ b/field_collection.module @@ -575,6 +575,43 @@ 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 fields in the collection to add URIs for image 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 ($info['type'] == 'image' && $image_field = &$this->$field_name) { + + // Add the URI to the field on the entity for display. + if (isset($image_field[$langcode])) { + foreach ($image_field[$langcode] as &$field_to_be_updated) { + if (!isset($field_to_be_updated['uri'])) { + $image = file_load($field_to_be_updated['fid']); + $field_to_be_updated['uri'] = $image->uri; + } + } + } + } + } + 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 -- 1.8.3.2