Many Drupal developers will agree that Feeds is the go-to module for importing content into Drupal. While it works great “out of the box” for importing spreadsheets, xml files, or nearly anything else you can throw at it, sometimes you need to do more than just save values to a field. What happens if you need to do some additional processing on the values before you save them?
I encountered this problem on a project where the client supplied content in a spreadsheet with a unique “sort by” field and an “antecedents” field that could be empty or contain the sort by values for one or more other pieces of content from the spreadsheet. Within Drupal, the antecedents were implemented as an entity reference field so I faced the challenge of mapping the list of “sort by” values to nodes during the import. The solution is to define a new mapping target that will handle any custom processing that needs to be done.
The feeds module provides hookfeedsprocessortargetsalter() which can be used to add new mapping targets. Using it to add a new mapping target is simply a matter of supplying a name and callback function for the target.
Once you’ve defined the target for feeds, you need to create the callback function that will handle whatever custom processing you need.
Now all that’s left is to enable your custom module and add a mapping to the new target.