diff --git a/mappers/file.inc b/mappers/file.inc index aa967b9..302b4b9 100644 --- a/mappers/file.inc +++ b/mappers/file.inc @@ -78,11 +78,25 @@ function file_feeds_set_target($source, $entity, $target, $value) { return; } - static $destination; - if (!$destination) { - $entity_type = $source->importer->processor->entityType(); - $bundle = $source->importer->processor->bundle(); + static $destinations = array(); + $entity_type = $source->importer->processor->entityType(); + + // $source->importer->processor->bundle() could break entityreference_feeds + // since $entity bundle (and type) could be different from importers bundle (and type) + // $source->importer->processor->entityType() is not safe either, + // but unfortunately no way to extract entity type from entity + list(, , $bundle) = entity_extract_ids($entity_type, $entity); + + if(!isset($destinations[$entity_type])) { + $destinations[$entity_type] = array(); + } + + if(!isset($destinations[$entity_type][$bundle])) { + $destinations[$entity_type][$bundle] = array(); + } + + if(!isset($destinations[$entity_type][$bundle][$field_name])) { $instance_info = field_info_instance($entity_type, $field_name, $bundle); // Determine file destination. @@ -91,8 +105,9 @@ function file_feeds_set_target($source, $entity, $target, $value) { if (!empty($entity->uid)) { $data[$entity_type] = $entity; } - $destination = file_field_widget_uri($info, $instance_info, $data); + $destinations[$entity_type][$bundle][$field_name] = file_field_widget_uri($info, $instance_info, $data); } + $destination = $destinations[$entity_type][$bundle][$field_name]; } // Populate entity.