? 849840-10_submit_full_mapping.patch ? feeds.849840.8.patch ? libraries/simplepie.inc Index: feeds_ui/feeds_ui.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds_ui/feeds_ui.admin.inc,v retrieving revision 1.35 diff -u -p -r1.35 feeds_ui.admin.inc --- feeds_ui/feeds_ui.admin.inc 10 Sep 2010 14:42:07 -0000 1.35 +++ feeds_ui/feeds_ui.admin.inc 10 Sep 2010 15:40:15 -0000 @@ -531,9 +531,6 @@ function feeds_ui_mapping_form(&$form_st if (is_array($mappings)) { foreach ($mappings as $i => $mapping) { - - $mappings[$i]['source'] = isset($source_options) ? $source_options[$mappings[$i]['source']] : $mappings[$i]['source']; - $mappings[$i]['target'] = isset($target_options[$mappings[$i]['target']]) ? $target_options[$mappings[$i]['target']] : $mappings[$i]['target']; $param = array( 'processor' => $importer->processor, 'mapping' => $mapping, @@ -574,7 +571,7 @@ function feeds_ui_mapping_form(&$form_st } $form['target'] = array( '#type' => 'select', - '#options' => array('' => t('Select a target')) + _feeds_ui_format_options($targets), + '#options' => array('' => t('Select a target')) + $target_options, ); $form['add'] = array( '#type' => 'submit', @@ -595,7 +592,13 @@ function feeds_ui_mapping_form(&$form_st function feeds_ui_mapping_form_add_submit($form, &$form_state) { $importer = $form['#importer']; try { - $importer->processor->addMapping($form_state['values']['source'], $form_state['values']['target']); + $mappings = $form['#mappings']; + $mappings[] = array( + 'source' => $form_state['values']['source'], + 'target' => $form_state['values']['target'], + 'unique' => FALSE, + ); + $importer->processor->addConfig(array('mappings' => $mappings)); $importer->processor->save(); drupal_set_message(t('Mapping has been added.')); } @@ -609,22 +612,25 @@ function feeds_ui_mapping_form_add_submi */ function feeds_ui_mapping_form_submit($form, &$form_state) { $processor = $form['#importer']->processor; - $mappings = $processor->config['mappings']; // We may set some unique flags to mappings that we remove in the subsequent // step, that's fine. + $mappings = $form['#mappings']; if (isset($form_state['values']['unique_flags'])) { foreach ($form_state['values']['unique_flags'] as $k => $v) { - $processor->setUnique($mappings[$k]['source'], $mappings[$k]['target'], $v); + $mappings[$k]['unique'] = $v; } } foreach ($form_state['values']['remove_flags'] as $k => $v) { if ($v) { - $processor->removeMapping($mappings[$k]['source'], $mappings[$k]['target']); + unset($mappings[$k]); + // Keep our keys clean. + $mappings = array_values($mappings); } } - drupal_set_message(t('Your changes have been saved.')); + $processor->addConfig(array('mappings' => $mappings)); $processor->save(); + drupal_set_message(t('Your changes have been saved.')); } /** @@ -777,9 +783,11 @@ function theme_feeds_ui_mapping_form($fo $rows = array(); if (is_array($form['#mappings'])) { foreach ($form['#mappings'] as $i => $mapping) { + // Some parsers do not define source options. + $source = isset($form['source']['#options'][$mapping['source']]) ? $form['source']['#options'][$mapping['source']] : $mapping['source']; $rows[] = array( - $mapping['source'], - $mapping['target'], + $source, + $form['target']['#options'][$mapping['target']], drupal_render($form['unique_flags'][$i]), drupal_render($form['remove_flags'][$i]), ); Index: plugins/FeedsDataProcessor.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsDataProcessor.inc,v retrieving revision 1.22 diff -u -p -r1.22 FeedsDataProcessor.inc --- plugins/FeedsDataProcessor.inc 9 Sep 2010 23:01:57 -0000 1.22 +++ plugins/FeedsDataProcessor.inc 10 Sep 2010 15:40:15 -0000 @@ -109,41 +109,6 @@ class FeedsDataProcessor extends FeedsPr } /** - * Override parent::addMapping() and create a new field for new mapping - * targets. - * - * @see getMappingTargets(). - */ - public function addMapping($source, $target, $unique = FALSE) { - if (empty($source) || empty($target)) { - return; - } - - // Create a new field with targets that start with "new:" - @list($new, $type) = explode(':', $target); - - if ($new == 'new') { - // Build a field name from the source key. - $field_name = data_safe_name($source); - // Get the full schema spec from data. - $type = data_get_field_definition($type); - // Add the field to the table. - $schema = $this->table()->get('table_schema'); - if (!isset($schema['fields'][$field_name])) { - $target = $this->table()->addField($field_name, $type); - // Let the user know. - drupal_set_message(t('Created new field "!name".', array('!name' => $field_name))); - } - else { - throw new Exception(t('Field !field_name already exists as a mapping target. Remove it from mapping if you would like to map another source to it. Remove it from !data_table table if you would like to change its definition.', array('!field_name' => $field_name, '!data_table' => l($this->table()->get('name'), 'admin/content/data')))); - } - } - - // Let parent populate the mapping configuration. - parent::addMapping($source, $target, $unique); - } - - /** * Return available mapping targets. */ public function getMappingTargets() { @@ -367,4 +332,49 @@ class FeedsDataProcessor extends FeedsPr ), ); } + + /** + * Override parent::addConfig(). + */ + public function addConfig($config) { + $this->processMappings($config); + return parent::addConfig($config); + } + + /** + * Override parent::setConfig(). + */ + public function setConfig($config) { + $this->processMappings($config); + return parent::setConfig($config); + } + + /** + * Create a new field for each new: mapping. + */ + protected function processMappings(&$config) { + if (!empty($config['mappings'])) { + foreach ($config['mappings'] as &$mapping) { + @list($new, $type) = explode(':', $mapping['target']); + + // Create a new field with targets that start with "new:" + if ($new == 'new') { + // Build a field name from the source key. + $field_name = data_safe_name($mapping['source']); + // Get the full schema spec from data. + $type = data_get_field_definition($type); + // Add the field to the table. + $schema = $this->table()->get('table_schema'); + if (!isset($schema['fields'][$field_name])) { + $mapping['target'] = $this->table()->addField($field_name, $type); + // Let the user know. + drupal_set_message(t('Created new field "!name".', array('!name' => $field_name))); + } + else { + throw new Exception(t('Field !field_name already exists as a mapping target. Remove it from mapping if you would like to map another source to it. Remove it from !data_table table if you would like to change its definition.', array('!field_name' => $field_name, '!data_table' => l($this->table()->get('name'), 'admin/content/data')))); + } + } + } + } + } } Index: plugins/FeedsProcessor.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsProcessor.inc,v retrieving revision 1.17 diff -u -p -r1.17 FeedsProcessor.inc --- plugins/FeedsProcessor.inc 7 Sep 2010 17:57:15 -0000 1.17 +++ plugins/FeedsProcessor.inc 10 Sep 2010 15:40:15 -0000 @@ -169,54 +169,6 @@ abstract class FeedsProcessor extends Fe } /** - * Add a mapping to existing mappings. - * - * @param $source - * A string that identifies a source element. - * @param $target - * A string that identifies a target element. - * @param $unique - * A boolean that defines whether the target value should be unique. If - * TRUE only one item with a given target value can exist on the local - * system. Compare with existingItemId() and uniqueTargets(). - */ - public function addMapping($source, $target, $unique = FALSE) { - if (!empty($source) && !empty($target)) { - $this->config['mappings'][] = array( - 'source' => $source, - 'target' => $target, - 'unique' => $unique, - ); - } - } - - /** - * Set unique state of a mapping target. - */ - public function setUnique($source, $target, $unique) { - if (!empty($source) && !empty($target)) { - foreach ($this->config['mappings'] as $k => $mapping) { - if ($mapping['source'] == $source && $mapping['target'] == $target) { - $this->config['mappings'][$k]['unique'] = $unique; - } - } - } - } - - /** - * Remove a mapping. - */ - public function removeMapping($source, $target) { - foreach ($this->config['mappings'] as $k => $mapping) { - if ($mapping['source'] == $source && $mapping['target'] == $target) { - unset($this->config['mappings'][$k]); - } - } - // Keep or keys clean. - $this->config['mappings'] = array_values($this->config['mappings']); - } - - /** * Get mappings. */ public function getMappings() {