Posted by twistor on November 26, 2010 at 7:57am
28 followers
| Project: | Feeds |
| Version: | 7.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Currently, if you map to a field more than one time, each successive mapping will override the previous one. This can even lead to odd behavior if the first source contained more values than the second.
As per some discussion in #860748: Config for mappers?.
Comments
#1
This patch tries to change as little of the logic as possible. I think it might be better to check the type in field_feeds_set_target_text and not in _field_feeds_set_target at all. It comes down to whether we should try to enforce type or let the field implementations handle it.
If we go this route, most (guessing) of the target mappers will have to change and we should be careful as these will be references for anyone else implementing them. Most of them are copy-paste jobs as it is. It should also be documented that this is the required behavior.
#2
#3
subscribe
#4
This is how it was done for the 6.x version: #873198: Import multiple values to tag vocabulary
#5
subscribe
#6
I'm not a programmer, and I still don't know how to create a patch after all this time. But here is how I solved this problem when I ran up against it today. Since I was using a semicolon as my field deliminator, I could use a comma to separate the multiple values. I know it's not a final solution, but thought it might help someone.
I changed the follow function in the mappers/field.inc.
/*** Callback for mapping text fields.
*/
function field_feeds_set_target_text($source, $entity, $target, $value) {
$info = field_info_field($target);
if ($info['cardinality'] == -1) {
$value = preg_split("/[,]/", $value);
}
if (!is_array($value)) {
$value = array($value);
}
_field_feeds_set_target($source, $entity, $target, $value, TRUE);
}
#7
Hi , Exist a equivalent on drupal 6.x for field_info_field($target) ?
Thanks
#8
hook_feeds_after_parse() may be of help here. Please read http://drupal.org/node/1360518.
#9
Marking #1231522: Having multiple values in a CSV imported into one target value. as a duplicate of this issue.
#10
Tested patch in #1 and works great for mapping multiple sources to the same target field (tested with a multivalue text field)
#11
I Was looking for a solution for this as well and found that using Feeds tamper you can accomplish this through the following procedure.
Because the last field overwrites all previous submissions when mapping multiple fields to one field (in my case a free tagging multiple value taxonomy field)
Step 1 Use the "rewrite" filter on de last mapper that submits to the field you map to your target field. Select al the required fields that you like to include using the replacement patterns and separate them by a comma,
Step 2 Add a "Explode" filter, and leave the comma as "String separator"
Make sure these filters are in this order ( 1.rewrite 2.explode) that's it you can now map multiple value sources to one target field.
#12
There is one additional caveat here -
It seems feeds tamper goes in alphabetical order for some things - If you are using Feeds Tamper to do any sort of field alteration (find and replace, convert to boolean, etc) You need to make sure the "last mapper" is also the last field alphabetically. Otherwise your field alterations will not happen before the "rewrite" filter on the "last mapper".
#13
Feeds tamper does it in perfection. its kind of weird, the logic i mean, but in the end it will do the job.
Great module.
Thanks for the tip.
#14
#11 - great tip - thank you!
#15
#11 is a nice tip. Tested on a free tagging multiple value taxonomy field.
One thing though: the first field is inserted without the explode. So if I have a first field with (term1,term2) and a second field with (term3,term4) the inserted terms will be:
- term1,term2
- term1
- term2
- term3
- term4
If I set an explode tamper on the first field, and use that in the second field, the inserted terms will be:
- array
- term1
- term2
- term3
- term4
#16
hook_feeds_after_parse() from #8 helped me here. Thanks.
#17
Has this functionality been committed to the module d7 version or does it require the patch ?
does patch in #1 work for d7 dev
Because i cannot get this to work
I am trying to import a csv
I have a 5 radio button field that I am trying to populate
- update 02/12/13
I got it to work by just using explode and no rewrite plugin
#18
#11 made my day!
#19
I just figured out how to map multi-files (multiple columns in CSV file) to the same target. Hope it helps anyone.
D7 mappers/file.inc
// @todo This needs review and debugging.
list($entity_id, $vid, $bundle_name) = entity_extract_ids($entity->feeds_item->entity_type, $entity);
$instance_info = field_info_instance($entity->feeds_item->entity_type, $target, $bundle_name);
$info = field_info_field($target);
$data = array();
if (!empty($entity->uid)) {
$data[$entity->feeds_item->entity_type] = $entity;
}
$destination = file_field_widget_uri($info, $instance_info, $data);
// Populate entity.
// $i = 0;
$field = isset($entity->$target) ? $entity->$target : array();
foreach ($value as $v) {
try {
$file = $v->getFile($destination);
}
catch (Exception $e) {
watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
}
$fid = $file->fid; // ++++++++++++
if ($file) {
// $field['und'][$i]= (array)$file;
// $field['und'][$i]['display'] = 1; // @todo: Figure out how to properly populate this field.
$field['und'][] = array('fid'=> $fid, 'display'=> 1); //+++++++++++++
if ($info['cardinality'] == 1) {
break;
}
// $i++;
}