Skip to content

Instantly share code, notes, and snippets.

@chrisjlee
Created October 6, 2011 21:07
Show Gist options
  • Save chrisjlee/1268670 to your computer and use it in GitHub Desktop.
Save chrisjlee/1268670 to your computer and use it in GitHub Desktop.
Append.inc plugin for feeds_tamper plugin
<?php
/**
* @file
* Copy value from one source to another.
*/
$plugin = array(
'form' => 'feeds_tamper_append_form',
'callback' => 'feeds_tamper_append_callback',
'name' => 'Append source value',
'multi' => 'direct',
);
function feeds_tamper_append_form($importer, $element_key, $settings) {
$form = $sources = array();
$source_configs = $importer->parser->getMappingSources();
foreach ($importer->processor->config['mappings'] as $mapping) {
$sources[$mapping['source']] = isset($source_configs[$mapping['source']]) ? $source_configs[$mapping['source']]['name'] : $mapping['source'];
}
$form['to_from'] = array(
'#title' => t('To or from'),
'#type' => 'radios',
'#default_value' => isset($settings['to_from']) ? $settings['to_from'] : 'to',
'#options' => array('to' => t('To'), 'from' => t('From')),
'#description' => t('Select whether this source value should be appended <em>to</em> another source, or <em>from</em> another source to this one.'),
);
$form['source'] = array(
'#type' => 'radios',
'#default_value' => isset($settings['source']) ? $settings['source'] :key($sources),
'#options' => $sources,
'#title' => t('Source'),
);
return $form;
}
function feeds_tamper_append_callback($result, $item_key, $element_key, &$field, $settings) {
switch ($settings['to_from']) {
case 'to':
$result->items[$item_key][$settings['source']] = $field . $result->items[$item_key][$settings['source']];
return;
case 'from':
$field = $field . $result->items[$item_key][$settings['source']];
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment