protected function FeedsProcessor::map in Feeds 7.2
Same name and namespace in other branches
- 6 plugins/FeedsProcessor.inc \FeedsProcessor::map()
- 7 plugins/FeedsProcessor.inc \FeedsProcessor::map()
Execute mapping on an item.
This method encapsulates the central mapping functionality. When an item is processed, it is passed through map() where the properties of $source_item are mapped onto $target_item following the processor's mapping configuration.
For each mapping FeedsParser::getSourceElement() is executed to retrieve the source element, then FeedsProcessor::setTargetElement() is invoked to populate the target item properly. Alternatively a hook_x_targets_alter() may have specified a callback for a mapping target in which case the callback is asked to populate the target item instead of FeedsProcessor::setTargetElement().
See also
hook_feeds_parser_sources_alter()
hook_feeds_processor_targets()
hook_feeds_processor_targets_alter()
Related topics
2 calls to FeedsProcessor::map()
- FeedsProcessor::process in plugins/
FeedsProcessor.inc - Process the result of the parsing stage.
- FeedsUserProcessor::map in plugins/
FeedsUserProcessor.inc - Overrides FeedsProcessor::map().
1 method overrides FeedsProcessor::map()
- FeedsUserProcessor::map in plugins/
FeedsUserProcessor.inc - Overrides FeedsProcessor::map().
File
- plugins/
FeedsProcessor.inc, line 861 - Contains FeedsProcessor and related classes.
Class
- FeedsProcessor
- Abstract class, defines interface for processors.
Code
protected function map(FeedsSource $source, FeedsParserResult $result, $target_item = NULL) {
$targets = $this
->getCachedTargets();
// Get fields for the entity type we are mapping to.
$fields = field_info_instances($this
->entityType(), $this
->bundle());
if (empty($target_item)) {
$target_item = array();
}
// Many mappers add to existing fields rather than replacing them. Hence we
// need to clear target elements of each item before mapping in case we are
// mapping on a prepopulated item such as an existing node.
foreach ($this
->getMappings() as $mapping) {
if (isset($targets[$mapping['target']]['real_target'])) {
$target_name = $targets[$mapping['target']]['real_target'];
}
else {
$target_name = $mapping['target'];
}
// If the target is a field empty the value for the targeted language
// only.
// In all other cases, just empty the target completely.
if (isset($fields[$target_name])) {
// Empty the target for the specified language.
$target_item->{$target_name}[$mapping['language']] = array();
}
else {
// Empty the whole target.
$target_item->{$target_name} = NULL;
}
}
// This is where the actual mapping happens: For every mapping we invoke
// the parser's getSourceElement() method to retrieve the value of the
// source element and pass it to the processor's setTargetElement() to stick
// it on the right place of the target item.
foreach ($this
->getMappings() as $mapping) {
$value = $this
->getSourceValue($source, $result, $mapping['source']);
$this
->mapToTarget($source, $mapping['target'], $target_item, $value, $mapping);
}
return $target_item;
}