I want to import the fields "alt", "title" and the custom field "copyright_notice" via feeds using the following code:
function budg_eu_projects_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 ($info['type'] == 'file') {
$targets[$name . ':alt'] = array(
'name' => t('@label: Alt', array('@label' => $instance['label'])),
'callback' => 'budg_eu_projects_set_target',
'description' => t('The alt tag of the @label field.', array('@label' => $instance['label'])),
'real_target' => $name,
);
$targets[$name . ':title'] = array(
'name' => t('@label: Title', array('@label' => $instance['label'])),
'callback' => 'budg_eu_projects_set_target',
'description' => t('The title of the @label field.', array('@label' => $instance['label'])),
'real_target' => $name,
);
$targets[$name . ':copyright_notice'] = array(
'name' => t('@label: Copyright Notice', array('@label' => $instance['label'])),
'callback' => 'budg_eu_projects_set_target',
'description' => t('The title of the @label field.', array('@label' => $instance['label'])),
'real_target' => $name,
);
}
}
return $targets;
}
As a callback function I use
/**
* Callback for mapping file fields.
*/
function budg_eu_projects_set_target(FeedsSource $source, $entity, $target, array $values) {
list($field_name, $sub_field) = explode(':', $target . ':uri');
$info = field_info_field($field_name);
// Populate entity.
$field = isset($entity->$field_name) ? $entity->$field_name : array(LANGUAGE_NONE => array());
$delta = 0;
foreach ($values as $v) {
if ($info['cardinality'] == $delta) {
break;
}
if (!isset($field[LANGUAGE_NONE][$delta])) {
$field[LANGUAGE_NONE][$delta] = array();
}
$field[LANGUAGE_NONE][$delta][$sub_field] = $v;
$delta++;
}
$entity->$field_name = $field;
}
I managed to add the fields as a mapping target but the data of the fields are not saved. What is missing?
Thanks Rainer
$values
but don't use the value to set anything. Maybe adding$field[LANGUAGE_NONE][$delta][$sub_field] = $v;
before$delta++;
would help?