Commit d5632e5b authored by metzlerd's avatar metzlerd
Browse files

Refactor config and add support for field mapping config.

parent d1e46bf0
......@@ -7,10 +7,14 @@ class FeedsForenaXMLParser extends FeedsParser {
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$source_config = $source->getConfigFor($this);
$result = new FeedsParserResult();
$fields = @$source_config['fields'];
$parser = Frx::Fields($fields);
// Load and configure parser.
$xpath = @$source_config['xpath'] ? $source_config['xpath'] : '*';
$xpath = @$this->config['xpath'];
$options = @$this->config['options'];
$options = @drupal_parse_info_format($source_config['options']);
$fields = @$options['fields'];
if (!$fields) $fields= array();
$format = @!$options['format'];
$raw = $fetcher_result->getRaw();
$mappings = feeds_importer($this->id)->processor->config['mappings'];
......@@ -23,7 +27,7 @@ class FeedsForenaXMLParser extends FeedsParser {
$item = array();
foreach($mappings as $field) {
$text = $field['source'];
$item[$text] = $parser->render($text);
$item[$text] = $parser->render($text, !$format);
}
$result->items[] = $item;
Frx::Data()->pop();
......@@ -34,56 +38,13 @@ class FeedsForenaXMLParser extends FeedsParser {
}
/**
* Define defaults.
*/
public function sourceDefaults() {
return array(
'xplath' => $this->config['xpath'],
);
}
/**
* Source form.
*
* Show mapping configuration as a guidance for import form users.
*/
public function sourceForm($source_config) {
$form = array();
$form['#weight'] = -10;
$mappings = feeds_importer($this->id)->processor->config['mappings'];
$sources = $uniques = array();
foreach ($mappings as $mapping) {
$sources[] = check_plain($mapping['source']);
if (!empty($mapping['unique'])) {
$uniques[] = check_plain($mapping['source']);
}
}
$items = array();
$items[] = format_plural(count($uniques), t('Column <strong>!column</strong> is mandatory and considered unique: only one item per !column value will be created.', array('!column' => implode(', ', $uniques))), t('Columns <strong>!columns</strong> are mandatory and values in these columns are considered unique: only one entry per value in one of these column will be created.', array('!columns' => implode(', ', $uniques))));
$form['help'] = array(
'list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
);
$form['xpath'] = array(
'#type' => 'textfield',
'#title' => t('XPath Expression'),
'#description' => t('Specify an xpath expression that will be used to break up the data into feed items. When in doubt use * '),
'#default_value' => isset($source_config['xpath']) ? $source_config['xpath'] : '*',
);
return $form;
}
/**
* Define default configuration.
*/
public function configDefaults() {
return array(
'xpath' => '*',
'options' => '',
);
}
......@@ -95,10 +56,20 @@ class FeedsForenaXMLParser extends FeedsParser {
$form = array();
$form['xpath'] = array(
'#type' => 'textfield',
'#title' => t('XPath Expression'),
'#title' => t('Default XPath Expression'),
'#description' => t('Specify an xpath expression that will be used to break up the data into feed items. When in doubt use * '),
'#default_value' => $this->config['xpath'],
);
$form['options'] = array(
'#type' => 'textarea',
'#title' => t('Default Formatting Option '),
'#description' => t('Specify the field configuration options to be used when specifying the data. The format
used is the same as in .info files with falues for the FRX files. (e.g. fields[date_taken][format] = iso_date )'),
'#default_value' => $this->config['options'],
'#rows' => 20,
'#maxlength' => NULL,
'#required' => FALSE,
);
return $form;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment