function commerce_file_set_data_target in Commerce File 7
License data target callback for hook_feeds_processor_targets_alter().
Parameters
$source: Field mapper source settings.
$entity: An entity object, for instance a node object.
$target: A string identifying the target on the entity.
$value: The value to populate the target with.
1 string reference to 'commerce_file_set_data_target'
File
- ./
commerce_file.feeds.inc, line 236 - Integration with the Feeds module.
Code
function commerce_file_set_data_target($source, $entity, $target, $value) {
list($field_name, $field_data_name, $property_name) = explode(':', $target, 3);
// Handle non-multiple value fields.
if (!is_array($value)) {
$value = array(
$value,
);
}
$field = isset($entity->{$field_name}) ? $entity->{$field_name} : array();
$field_info = field_info_field($field_name);
$singular = $field_info['cardinality'] == 1;
$lang = LANGUAGE_NONE;
foreach ($value as $i => $v) {
$field[$lang][$i][$field_data_name][$property_name] = $v;
if ($singular) {
break;
}
}
$entity->{$field_name} = $field;
}