function feeds_ui_mapping_form in Feeds 7
Same name and namespace in other branches
- 8.2 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()
- 6 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()
- 7.2 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()
Edit mapping.
@todo Completely merge this into config form handling. This is just a shared form of configuration, most of the common functionality can live in FeedsProcessor, a flag can tell whether mapping is supported or not.
1 string reference to 'feeds_ui_mapping_form'
- feeds_ui_edit_page in feeds_ui/
feeds_ui.admin.inc - Edit feed configuration.
File
- feeds_ui/
feeds_ui.admin.inc, line 484 - Contains all page callbacks, forms and theming functions for Feeds administrative pages.
Code
function feeds_ui_mapping_form($form, &$form_state, $importer) {
drupal_add_js(drupal_get_path('module', 'feeds_ui') . '/feeds_ui.js');
$form = array();
$form['#importer'] = $importer;
$form['#mappings'] = $mappings = $importer->processor
->getMappings();
$form['help']['#markup'] = feeds_ui_mapping_help();
// Get mapping sources from parsers and targets from processor, format them
// for output.
// Some parsers do not define mapping sources but let them define on the fly.
if ($sources = $importer->parser
->getMappingSources()) {
$source_options = _feeds_ui_format_options($sources);
foreach ($sources as $k => $source) {
$legend['sources'][$k]['name']['#markup'] = empty($source['name']) ? $k : $source['name'];
$legend['sources'][$k]['description']['#markup'] = empty($source['description']) ? '' : $source['description'];
}
}
else {
$legend['sources']['#markup'] = t('This parser supports free source definitions. Enter the name of the source field in lower case into the Source text field above.');
}
$targets = $importer->processor
->getMappingTargets();
$target_options = _feeds_ui_format_options($targets);
foreach ($targets as $k => $target) {
$legend['targets'][$k]['name']['#markup'] = empty($target['name']) ? $k : $target['name'];
$legend['targets'][$k]['description']['#markup'] = empty($target['description']) ? '' : $target['description'];
}
// Legend explaining source and target elements.
$form['legendset'] = array(
'#type' => 'fieldset',
'#title' => t('Legend'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$form['legendset']['legend'] = $legend;
// Add unique and remove forms to mappings.
$form['unique_flags'] = $form['remove_flags'] = array(
'#tree' => TRUE,
);
if (is_array($mappings)) {
foreach ($mappings as $i => $mapping) {
$param = array(
'processor' => $importer->processor,
'mapping' => $mapping,
);
if (isset($targets[$mapping['target']]['optional_unique']) && $targets[$mapping['target']]['optional_unique'] === TRUE) {
$form['unique_flags'][$i] = array(
'#type' => 'checkbox',
'#default_value' => !empty($mapping['unique']),
'#attributes' => array(
'class' => array(
'feeds-ui-trigger-submit',
),
),
);
}
$form['remove_flags'][$i] = array(
'#type' => 'checkbox',
'#title' => t('Remove'),
'#prefix' => '<div class="feeds-ui-checkbox-link">',
'#suffix' => '</div>',
);
}
}
if (isset($source_options)) {
$form['source'] = array(
'#type' => 'select',
'#options' => array(
'' => t('Select a source'),
) + $source_options,
);
}
else {
$form['source'] = array(
'#type' => 'textfield',
'#size' => 20,
'#default_value' => t('Name of source field'),
'#attributes' => array(
'class' => array(
'hide-text-on-focus',
),
),
);
}
$form['target'] = array(
'#type' => 'select',
'#options' => array(
'' => t('Select a target'),
) + $target_options,
);
$form['add'] = array(
'#type' => 'submit',
'#value' => t('Add'),
'#submit' => array(
'feeds_ui_mapping_form_add_submit',
),
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => array(
'class' => array(
'feeds-ui-hidden-submit',
),
),
);
return $form;
}