function feeds_excel_form_alter in Feeds Excel 7
Same name and namespace in other branches
- 6 feeds_excel.module \feeds_excel_form_alter()
Implements hook_form_alter().
Adds token legend to feeds UI mapping form, as its not possibel via any feeds parser method.
File
- ./
feeds_excel.module, line 54
Code
function feeds_excel_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'feeds_ui_mapping_form') {
// We only extend the mapping form, if there is an importer.
if (empty($form['#importer'])) {
watchdog("feeds_excel", "No #importer specified in form. Will not apply excel feed processing.");
return;
}
try {
$importer = feeds_importer($form['#importer']);
} catch (Exception $e) {
watchdog("feeds_excel", "Failed to load importer %id", array(
'id' => $form['#importer'],
));
}
$config = $importer
->getConfig();
if ($config['parser']['plugin_key'] == 'ExcelParser') {
$form['legend_sources'] = array(
'#type' => 'fieldset',
'#title' => t('Legend sources'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 50,
);
$form['save']['#weight'] = 99;
if (module_exists('token')) {
$form['legend_sources']['#description'] = t('Use the listed tokens as source, to import the corresponding values to the selected target.');
$token_types = array(
'excel-file',
'excel-sheet',
);
switch ($config['parser']['config']['mapping_mode']) {
case 'rows':
$token_types[] = 'excel-row';
break;
case 'columns':
$token_types[] = 'excel-column';
break;
}
if ($config['content_type']) {
$token_types[] = 'node';
}
$form['legend_sources']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => $token_types,
'#global_types' => TRUE,
);
}
else {
$form['legend_sources']['#description'] = t('Enable the !token module to see the list of available tokens.', array(
'!token' => l('Token', 'http://drupal.org/project/token'),
));
}
}
}
}