function feeds_tamper_ui_list_form in Feeds Tamper 6
Same name and namespace in other branches
- 7 feeds_tamper_ui/feeds_tamper_ui.admin.inc \feeds_tamper_ui_list_form()
@file Forms and their accompanying validation and submit functions for Feeds Tamper UI.
1 string reference to 'feeds_tamper_ui_list_form'
- feeds_tamper_ui_menu in feeds_tamper_ui/
feeds_tamper_ui.module - Implementation of hook_menu().
File
- feeds_tamper_ui/
feeds_tamper_ui.admin.inc, line 9 - Forms and their accompanying validation and submit functions for Feeds Tamper UI.
Code
function feeds_tamper_ui_list_form(&$form_state, $importer) {
drupal_add_css(drupal_get_path('module', 'feeds_tamper_ui') . '/feeds_tamper_ui.css');
$mappings = $importer->processor->config['mappings'];
$sources = $importer->parser
->getMappingSources();
$targets = $importer->processor
->getMappingTargets();
$instances = feeds_tamper_load_by_importer($importer->id, TRUE);
// Help message at the top. I have a seceret, I added the link back to the
// mappings because it makes my life a lot easier while testing this.
$link = l(t('mapping'), FEEDS_TAMPER_UI_FEEDS_BASE . '/edit/' . $importer->id . '/mapping');
$message = 'Configure plugins to modify Feeds data before it gets saved. Each !mapping can be manipulated individually.';
$message = t($message, array(
'!mapping' => $link,
));
$form['help']['#markup'] = '<div class="help"><p>' . $message . '</p></div>';
$form['mappings'] = array();
// Helpful shortcut.
$map =& $form['mappings'];
$form['#importer'] = $importer;
foreach ($mappings as $mapping) {
$source = $mapping['source'];
$target = $mapping['target'];
// We will skip building the table if it has been built for a source, but
// we need to add the target label to indicate to the user that more than
// one field will be affected.
$target_label = !empty($targets[$target]['name']) ? check_plain($targets[$target]['name']) : check_plain($target);
$map[$source]['#title']['targets'][] = $target_label;
// We don't need to build the table again for this source.
if (isset($map[$source]['table'])) {
continue;
}
$source_label = !empty($sources[$source]['name']) ? check_plain($sources[$source]['name']) : check_plain($source);
$map[$source]['#title']['source'] = $source_label;
$map[$source]['#tree'] = TRUE;
$map[$source]['table'] = array();
// "Add plugin" link.
$add = FEEDS_TAMPER_UI_BASE . '/add/' . $importer->id . '/' . bin2hex($source);
$map[$source]['#add_link'] = l(t('Add plugin'), $add);
// There are no plugins for this source. We've built all we need to.
if (!isset($instances[$source])) {
continue;
}
foreach ($instances[$source] as $instance) {
// Plugin instance description.
$description = !empty($instance->description) ? check_plain($instance->description) : $instance->id;
$map[$source]['table'][$instance->id]['#description'] = $description;
// Weight field.
$map[$source]['table'][$instance->id]['weight'] = array(
'#type' => 'textfield',
'#size' => 5,
'#default_value' => $instance->weight,
'#attributes' => array(
'class' => 'weight',
),
);
// Name of plugin.
$plugin = feeds_tamper_get_plugin($instance->plugin_id);
$map[$source]['table'][$instance->id]['#name'] = $plugin['name'];
// Calculate where the plugin lives and it's corresponding operations.
if ($instance->export_type == EXPORT_IN_CODE) {
$status = t('Default');
$edit = t('Override');
$delete = '';
}
elseif ($instance->export_type == EXPORT_IN_DATABASE) {
$status = t('Normal');
$edit = t('Edit');
$delete = t('Delete');
}
elseif ($instance->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
$status = t('Overridden');
$edit = t('Edit');
$delete = t('Revert');
}
// Status column, Default, Normal, Overridden.
$map[$source]['table'][$instance->id]['#status'] = $status;
// Build Edit | Delete, Edit | Revert, Override links.
$ops = l(t($edit), FEEDS_TAMPER_UI_BASE . '/edit/' . $instance->id);
// Plugins provided in code can't be deleted but they can be reverted.
if (!empty($delete)) {
$ops .= ' | ';
$ops .= l(t($delete), FEEDS_TAMPER_UI_BASE . '/delete/' . $instance->id);
}
$map[$source]['table'][$instance->id]['#edit'] = $ops;
// Enable/disable checkbox.
$map[$source]['table'][$instance->id]['enabled'] = array(
'#type' => 'checkbox',
'#default_value' => !$instance->disabled,
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}