public function FeedsCSVParser::sourceForm in Feeds 6
Same name and namespace in other branches
- 7.2 plugins/FeedsCSVParser.inc \FeedsCSVParser::sourceForm()
- 7 plugins/FeedsCSVParser.inc \FeedsCSVParser::sourceForm()
Source form.
Show mapping configuration as a guidance for import form users.
Overrides FeedsPlugin::sourceForm
File
- plugins/
FeedsCSVParser.inc, line 102
Class
- FeedsCSVParser
- Parses a given file as a CSV file.
Code
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 ($mapping['unique']) {
$uniques[] = check_plain($mapping['source']);
}
}
$items = array(
t('Import !csv_files with one or more of these columns: !columns.', array(
'!csv_files' => l(t('CSV files'), 'http://en.wikipedia.org/wiki/Comma-separated_values'),
'!columns' => implode(', ', $sources),
)),
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']['#value'] = '<div class="help">' . theme('item_list', $items) . '</div>';
$form['delimiter'] = array(
'#type' => 'select',
'#title' => t('Delimiter'),
'#description' => t('The character that delimits fields in the CSV file.'),
'#options' => array(
',' => ',',
';' => ';',
'TAB' => 'TAB',
),
'#default_value' => isset($source_config['delimiter']) ? $source_config['delimiter'] : ',',
);
$form['no_headers'] = array(
'#type' => 'checkbox',
'#title' => t('No Headers'),
'#description' => t('Check if the imported CSV file does not start with a header row. If checked, mapping sources must be named \'0\', \'1\', \'2\' etc.'),
'#default_value' => isset($source_config['no_headers']) ? $source_config['no_headers'] : 0,
);
return $form;
}