public function FeedsDataProcessor::setTargetElement in Feeds 6
Set target element, bring element in a FeedsDataHandler format.
Overrides FeedsProcessor::setTargetElement
File
- plugins/
FeedsDataProcessor.inc, line 176 - Definition of FeedsDataProcessor.
Class
- FeedsDataProcessor
- Creates simple table records from feed items. Uses Data module.
Code
public function setTargetElement(&$target_item, $target_element, $value) {
if ($value === NULL) {
return;
}
if (strpos($target_element, '.')) {
/**
* Add field in FeedsDataHandler format.
*
* This is the tricky part, FeedsDataHandler expects an *array* of records
* at #[joined_table_name]. We need to iterate over the $value that has
* been mapped to this element and create a record array from each of
* them.
*/
list($table, $field) = explode('.', $target_element);
$values = array();
$value = is_array($value) ? $value : array(
$value,
);
foreach ($value as $v) {
// Create a record array.
$values[] = array(
$field => $v,
);
}
if (is_array($target_item["#{$table}"])) {
$target_item["#{$table}"] = array_merge($target_item["#{$table}"], $values);
}
else {
$target_item["#{$table}"] = $values;
}
}
else {
if (isset($target_item[$target_element]) && is_array($target_item[$target_element]) && is_array($value)) {
$target_item[$target_element] = array_merge($target_item[$target_element], $value);
}
else {
$target_item[$target_element] = $value;
}
}
}