Import data with feeds that is not in the source file I need support to set a field on a feeds mapping that is not in the source.

I already have some code that for some reason is not working.

If I use hook_feeds_after_parse, I can set the value but I need to use the method below (new mapping).

function  MYMODULE_cronapi($op, $job = NULL) {
    $items['TEST IMPORT'] = array(
        'description' =&gt; 'TEST IMPORT',
        'rule' =&gt; '1 * 1 * *',
        'callback' =&gt; ' MYMODULE_testImport',
    );

    return $items;
}

function MYMODULE_testImport() {
    $test_field_value = 'this is a test';
    $feeds_importer = 'test_feeds';
    $feeds_source = feeds_source($feeds_importer);
    $field_mappings = $feeds_source-&gt;importer-&gt;processor-&gt;getMappings();

    $path_to_xml = 'http://.../sites/default/files/test_content.xml';

    foreach ($field_mappings as &amp;$mapping) {
        if ($mapping['target'] == 'field_test_field') {
            $mapping['test_field'] = $test_field_value;
        }
    }

    $feeds_source-&gt;importer-&gt;processor-&gt;addConfig(array('mappings' =&gt; $field_mappings)); 

    drupal_static_reset('FeedsProcessor::getMappings');

    $feeds_config = $feeds_source-&gt;getConfigFor($feeds_source-&gt;importer-&gt;fetcher);

    $feeds_config['source'] = $path_to_xml;

    $config = array(
        'process_in_background' =&gt; TRUE,
    );

    $feeds_source-&gt;setConfigFor($feeds_source-&gt;importer-&gt;fetcher, $feeds_config);
    $feeds_source-&gt;importer-&gt;addConfig($config);
    $feeds_source-&gt;save();
    $feeds_source-&gt;startImport();

    while (FEEDS_BATCH_COMPLETE != $feeds_source-&gt;import());
}

function MYMODULE_feeds_processor_targets_alter(array &amp;$targets, $entity_type, $bundle) {
  if ($entity_type == 'node' &amp;&amp; $bundle == 'test_content') {
    if (isset($targets['field_test_field'])) {
      $targets['field_test_field']['callback'] = 'MYMODULE_set_test_field';
    }
  }
}

function MYMODULE_set_test_field(FeedsSource $source, $entity, $target, array $values, array $mapping) {
    if ($source-&gt;importer-&gt;id == 'test_feeds') {
        if (!empty($mapping['test_field'])) {
            $entity-&gt;{$target}[$entity-&gt;language][0]['value'] = $mapping['test_field'];
        }
    }
}
To get the importer's machine name from the source, instead of doing $source-&gt;id, this should be $source-&gt;importer-&gt;id.

I don't know what you are trying to do with $mapping['_ad_area'] exactly. $mapping contains target configuration (aka mapping settings). I don't see form_callbacks on your target code. The default taxonomy reference field also doesn't have an option called '_ad_area'. If you added mapping for the 'field_ad_area' target, values coming from the source should exist in $values.

You say you want to provide a value that is not in your original source. If this is a fixed value, you can use the Tamper plugin &quot;Set default value&quot; from the Feeds Tamper module. If you are using the CSV parser, on the mapping form you can just enter a source column name that does not exist in your CSV file. Otherwise, select &quot;Blank source&quot;.
If you programmatically want to set a value, you can implement the hook hook_feeds_after_parse() in a custom module:


/**
 * Implements hook_feeds_after_parse().
 */
function mymodule_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
  if ($source-&gt;importer-&gt;id != 'qc_data_generic_import') {
    return;
  }

  foreach ($result-&gt;items as &amp;$item) {
    $item['Blank source 1'] = 'My value';
  }
}