Last updated August 8, 2012. Created by juampy on December 4, 2011.
Edited by sprice. Log in to edit this page.
While setting up a feed, you may need to map, merge or process more than one field into a single field, no matter if the input is coming from columns from a CSV, tags from an XML or any other source.
Example
Suppose that our source is a very simple CSV where there is the following structure:
| Name | Surname |
| Iggy | Pop |
| Tom | Waits |
We want to merge both Name and Surname into a single field for our users table. Therefore, we will join this together into a new column "fullname" at hook_feeds_after_parse() and then define a mapper for this.
Here is the hook implementation:
/**
* Implements hook_feeds_after_parse()
*
* Adds a key "fullname" to each result
* @param $source
* FeedsSource object that describes the source that has been imported.
* @param $result
* FeedsParserResult object that has been parsed from the source.
*/
function mymodule_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
foreach($result->items as $key => $row) {
$result->items[$key]['fullname'] = $row['name'] . ' ' . $row['surname'];
}
}Then, when you are configuring the feed in the mappings page, you could now use the source 'fullname' and map it to the field Name of a user.
Comments
This can be done with feeds
This can be done with feeds tamper. By assigning both CSV fields to Temporary Values then calculate the final value inside the tamper and assign to your node.
- bbros.us -
Who else is interested in Lunch?
Help improving the docs
Great, could you edit the page and add it as an alternative method with a step list?