Add fields to feeds importer 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(&amp;$targets, $entity_type, $bundle_name) {
  foreach (field_info_instances($entity_type, $bundle_name) as $name =&gt; $instance) {

    $info = field_info_field($name);

    if ($info['type'] == 'file') {
      $targets[$name . ':alt'] = array(
        'name' =&gt; t('@label: Alt', array('@label' =&gt; $instance['label'])),
        'callback' =&gt; 'budg_eu_projects_set_target',
        'description' =&gt; t('The alt tag of the @label field.', array('@label' =&gt; $instance['label'])),
        'real_target' =&gt; $name,
      );
      $targets[$name . ':title'] = array(
        'name' =&gt; t('@label: Title', array('@label' =&gt; $instance['label'])),
        'callback' =&gt; 'budg_eu_projects_set_target',
        'description' =&gt; t('The title of the @label field.', array('@label' =&gt; $instance['label'])),
        'real_target' =&gt; $name,
      );
      $targets[$name . ':copyright_notice'] = array(
        'name' =&gt; t('@label: Copyright Notice', array('@label' =&gt; $instance['label'])),
        'callback' =&gt; 'budg_eu_projects_set_target',
        'description' =&gt; t('The title of the @label field.', array('@label' =&gt; $instance['label'])),
        'real_target' =&gt; $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-&gt;$field_name) ? $entity-&gt;$field_name : array(LANGUAGE_NONE =&gt; 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-&gt;$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
AFAICT the code you've posted will populate the entity with the values from the CSV file - but nothing's set up to persist those values. The Field API itself can persist values it knows about. Look at file_field_schema()

/**
 * Implements hook_field_schema().
 */
function file_field_schema($field) {
  return array(
    'columns' =&gt; array(
      'fid' =&gt; array(
        'description' =&gt; 'The {file_managed}.fid being referenced in this field.',
        ...
      ),
      'display' =&gt; array(
        'description' =&gt; 'Flag to control whether this file should be displayed when viewing content.',
        ...
      ),
      'description' =&gt; array(
        'description' =&gt; 'A description of the file.',
        ...
      ),
    ),
    ...
  );
}


Through this, the Field API knows to store the file ID, whether or not to show the file when viewing content, and a description of the file. Image field is very close to file field, and shares mostly the same code. And looking at image_field_schema() you can see where the title and alt fields come from.

/**
 * Implements hook_field_schema().
 */
function image_field_schema($field) {
  return array(
    'columns' =&gt; array(
      'fid' =&gt; array(
        'description' =&gt; 'The {file_managed}.fid being referenced in this field.',
        ...
      ),
      'alt' =&gt; array(
        'description' =&gt; "Alternative image text, for the image's 'alt' attribute.",
        ...
      ),
      'title' =&gt; array(
        'description' =&gt; "Image title text, for the image's 'title' attribute.",
        ...
      ),
      'width' =&gt; array(
        'description' =&gt; 'The width of the image in pixels.',
        ...
      ),
      'height' =&gt; array(
        'description' =&gt; 'The height of the image in pixels.',
        ...
      ),
    ),
    ...
  );
}


I think the right way forwards depends on your data model. In the example below there are two nodes with file fields, each referring to the same file. Note that they can have different alt and title fields even though they're referring to the same file.

Node 1:
  file_field:
    fid: 1
    alt: A beautiful beach
    title: Wish you were here?

Node 2:
  file_field:
    fid: 1
    alt: Great swimming
    title: Fun for all the family


The alternative I suggested in a comment was to add the fields to the entity itself.

File 1:
  alt: A beautiful beach
  title: Wish you were here?

Node 1:
  file_field:
    fid: 1

Node 2:
  file_field:
    fid: 1


This means the alt and title will always be the same for a given file. It's obviously for you to decide which model meets your needs more appropriately. If you want to store the data per-field (the first example) you have two choices:


Use an existing field and alter its schema with hook_schema_alter() - a bit painful as there's no hook_field_schema_alter(). Only do this if conceptually every instance of this field should have that extra data.
(I'd prefer this personally) Create a new field that stores the extra columns you're interested in. Image field is the perfect place to look for inspiration, because its functionality's based on file field and it has extra columns.


If you want to store the data per file entity, then you can use fieldable files and I'm fairly sure you should be able to set everything up through the feeds UI. (IE no need for the feeds code above.)