Skip to content
Snippets Groups Projects
Commit ebaf53fc authored by Alex Barth's avatar Alex Barth
Browse files

#840626 alevine, alex_b: Support using same mapping target multiple times.

parent e0064688
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
Feeds 6.x 1.X XXXX
------------------
- #840626 alevine, alex_b: Support using same mapping target multiple times.
- #624464 lyricnz, alex_b: Fix to "support tabs as delimiters".
- #840350 lyricnz: (Optionally) Transliterate enclosure filenames to provide
protection from awkward names.
......
......@@ -129,6 +129,9 @@ function hook_feeds_user_processor_targets_alter(&$targets) {
* Alter mapping targets for nodes. Use this hook to add additional target
* options to the mapping form of Node processors.
*
* If the key in $targets[] does not correspond to the actual key on the node
* object ($node->key), real_target MUST be specified. See mappers/link.inc
*
* For an example implementation, see mappers/content.inc
*
* @param &$targets
......@@ -144,6 +147,12 @@ function hook_feeds_node_processor_targets_alter(&$targets, $content_type) {
'description' => t('Description of what my custom node field does.'),
'callback' => 'my_callback',
);
$targets['my_node_field2'] = array(
'name' => t('My Second custom node field'),
'description' => t('Description of what my second custom node field does.'),
'callback' => 'my_callback2',
'real_target' => 'my_node_field_two', // Specify real target field on node.
);
}
/**
......
......@@ -23,11 +23,13 @@ function date_feeds_node_processor_targets_alter(&$targets, $content_type) {
'name' => $name .': Start',
'callback' => 'date_feeds_set_target',
'description' => t('The start date for the !name field. Also use if mapping both start and end.', array('!name' => $name)),
'real_target' => $field_name,
);
$targets[$field_name .':end'] = array(
'name' => $name .': End',
'callback' => 'date_feeds_set_target',
'description' => t('The end date for the @name field.', array('@name' => $name)),
'real_target' => $field_name,
);
}
}
......
......@@ -22,6 +22,7 @@ function link_feeds_node_processor_targets_alter($targets, $content_type) {
'name' => t('!field_name (URL)', array('!field_name' => $name)),
'callback' => 'link_feeds_set_target',
'description' => t('The URL for the CCK !name field of the node.', array('!name' => $name)),
'real_target' => $field_name,
);
//Provides a mapping target for the field title if used.
......@@ -30,6 +31,7 @@ function link_feeds_node_processor_targets_alter($targets, $content_type) {
'name' => $name .' (' . t('title').')',
'callback' => 'link_feeds_set_target',
'description' => t('The title for the CCK !name field of the node.', array('!name' => $name)),
'real_target' => $field_name,
);
}
}
......
......@@ -19,6 +19,7 @@ function taxonomy_feeds_node_processor_targets_alter(&$targets, $content_type) {
'name' => "Taxonomy: ". $vocab->name,
'callback' => 'taxonomy_feeds_set_target',
'description' => $description,
'real_target' => 'taxonomy',
);
}
}
......
......@@ -27,8 +27,10 @@ class FeedsDataProcessor extends FeedsProcessor {
// Map item to a data record, feed_nid and timestamp are mandatory.
$data = array();
$data['feed_nid'] = $source->feed_nid;
$data['timestamp'] = FEEDS_REQUEST_TIME;
$data = $this->map($item, $data);
if (!isset($data['timestamp'])) {
$data['timestamp'] = FEEDS_REQUEST_TIME;
}
// Only save if this item is not expired.
if ($expiry_time != FEEDS_EXPIRE_NEVER && $data['timestamp'] < (FEEDS_REQUEST_TIME - $expiry_time)) {
......
......@@ -95,6 +95,25 @@ abstract class FeedsProcessor extends FeedsPlugin {
$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.
if (is_array($target_item)) {
$target_item = (object)$target_item;
$convert_to_array = TRUE;
}
foreach ($targets[$this->id] as $target_name => $target) {
if (isset($target['real_target']) && isset($target_item->$target['real_target'])) {
unset($target_item->$target['real_target']);
}
else if (isset($target_item->$target_name)) {
unset($target_item->$target_name);
}
}
if ($convert_to_array) {
$target_item = (array)$target_item;
}
/*
This is where the actual mapping happens: For every mapping we envoke
the parser's getSourceElement() method to retrieve the value of the source
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment