Closed (duplicate)
Project:
Feeds
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 Aug 2011 at 19:48 UTC
Updated:
15 Mar 2013 at 10:40 UTC
My node has a field-collection field type (shirt). The field-collection "shirt" has three subfields - color, price, size.
I'm trying to create a mapper for these fields. Below is what I have so far (it's hard coded just to get it done and test). However, nothing appears in my mapping targets or in querypath to identify the source -- basically it's not working :0). I'm using QueryPath as the parser and NodeProcessor.
Please take a look and let me know where I'm going wrong. (Step two will be if it actually works with field-collection...but that's another issue).
shirt.inc file in feeds/mapper
/**
* For Field Collection mapper - Implements hook_feeds_processor_target_alter().
*
* @param $targets array of target fields
* @param $entity_type
* @param $bundle_name
*/
function shirt_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name){
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
$info = field_info_field($name);
if (in_array($info['type'], 'field_collection')) {
$callback = 'shirt_feeds_set_target';
$module = 'field_collection';
$field_name = 'field_shirt';
$targets[ $field_name .':field_color'] = array(
'name' => $module . " module: " . $field_name . '.' . t('color'),
'callback' => $callback,
'description' => t('The color for the field-collection of the node.'),
);
$targets[ $field_name .':field_price'] = array(
'name' => $module . " module: " . $field_name . '.' . t('price'),
'callback' => $callback,
'description' => t('The price for the field-collection of the node.'),
);
$targets[ $field_name .':field_size'] = array(
'name' => $module . " module: " . $field_name . '.' . t('size'),
'callback' => $callback,
'description' => t('The size for the field-collection of the node.'),
);
}
}
}
/**
* Callback for mapping. Here is where the actual mapping happens.
*
* When the callback is invoked, $target contains the name of the field the
* user has decided to map to and $value contains the value of the feed item
* element the user has picked as a source.
*/
function shirt_feeds_set_target($source, $entity, $target, $value) {
list($field_name, $sub_field) = explode(':', $target);
if (strpos($sub_field, '][') !== FALSE) {
list($sub_field, $last_field) = explode('][', $sub_field, 2);
}
if (!is_array($value)) {
$value = array($value);
}
foreach ($value as $i => $val) {
if (isset($last_field)) {
$entity->{$field_name}[$i][$sub_field][$last_field] = $val;
}
else {
$entity->{$field_name}[$i][$sub_field] = $val;
}
}
return $entity;
}
Comments
Comment #1
mrfelton commentedI suspect this will be solved when #1033202: [Meta] Generic entity processor lands.
Comment #2
gaëlgSee #1274580: integration with fields collection module
Comment #3
dasjo#1 would be my favorite + i guess this is the most active discussion: #1063434: Add Feeds integration to FieldCollection
Comment #4
finex commentedDid someone tried this http://drupal.org/project/field_collection_feeds ?Sorry, I didn't follow the link before :-)Comment #5
lotyrin commentedThis appears to be a duplicate of #1063434: Add Feeds integration to FieldCollection. Lets take any discussion there.