diff --git a/gathercontent.module b/gathercontent.module index c775199..1a037e8 100644 --- a/gathercontent.module +++ b/gathercontent.module @@ -900,12 +900,16 @@ function gathercontent_gathercontent_process_choice_radio_field(EntityMetadataWr */ function gathercontent_gathercontent_process_files_field(EntityMetadataWrapper &$node, $local_field_name, $gathercontent_field_name, $is_translatable = FALSE, $language = 'und', $files) { $found_files = array(); + $field_info = field_info_field($local_field_name); foreach ($files as $file) { if ($file->field === $gathercontent_field_name) { $found = FALSE; - foreach ($node->{$local_field_name}->value() as $file) { - if ($file['gathercontent_id'] === $file->id) { - $found = TRUE; + $files = $node->{$local_field_name}->value(); + if (is_array($files)) { + foreach ($node->{$local_field_name}->value() as $file) { + if ($file['gathercontent_id'] === $file->id) { + $found = TRUE; + } } } @@ -913,15 +917,28 @@ function gathercontent_gathercontent_process_files_field(EntityMetadataWrapper & $local_file = file_save_data(file_get_contents($file->url), 'public://' . $file->filename); $local_file->gathercontent_id = $file->id; file_save($local_file); - $found_files[] = array('fid' => $local_file->fid); + if ($field_info['type'] === 'file') { + $file_data = array('fid' => $local_file->fid, 'display' => TRUE); + } + else { + $file_data = array('fid' => $local_file->fid); + } + + $found_files[] = $file_data; } } } + + $is_multiple = $field_info['cardinality'] != 1; + if (!$is_multiple) { + $found_files = reset($found_files); + } + if ($is_translatable) { - $node->language($language)->{$local_field_name} = $found_files; + $node->language($language)->{$local_field_name}->set($found_files); } else { - $node->{$local_field_name} = $found_files; + $node->{$local_field_name}->set($found_files); } } @@ -1541,3 +1558,8 @@ function gathercontent_preprocess_views_view_table(&$variables) { break; } } + +function dummy() { + $field = field_info_field('field_image'); + dpm($field); +}