diff --git a/mappers/field.inc b/mappers/field.inc index 43d62c4..acc45b0 100644 --- a/mappers/field.inc +++ b/mappers/field.inc @@ -29,6 +29,7 @@ function field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_na 'text_long', 'text_with_summary', ); + $unique = array(); foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { $info = field_info_field($name); unset($callback); @@ -38,11 +39,20 @@ function field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_na if (in_array($info['type'], $string_types)) { $callback = 'field_feeds_set_target_text'; } + if (module_exists('unique_field')) { + $info = field_info_field($name); + $scope = variable_get('unique_field_scope_'. $bundle_name, UNIQUE_FIELD_SCOPE_TYPE); + $unique[$name] = (($scope == UNIQUE_FIELD_SCOPE_TYPE || $scope == UNIQUE_FIELD_SCOPE_ALL) && in_array($name, variable_get('unique_field_fields_' . $bundle_name, array()))); + } + else { + $unique[$name] = FALSE; + } if (isset($callback)) { $targets[$name] = array( 'name' => check_plain($instance['label']), 'callback' => $callback, 'description' => t('The @label field of the node.', array('@label' => $instance['label'])), + 'optional_unique' => $unique[$name], ); } } diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index 25dac27..70e3cb7 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -279,6 +279,11 @@ class FeedsNodeProcessor extends FeedsProcessor { $nid = db_query("SELECT fs.feed_nid FROM {node} n JOIN {feeds_source} fs ON n.nid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(':id' => $id, ':source' => $value))->fetchField(); } break; + default: + if (module_exists('unique_field')) { + $scope = variable_get('unique_field_scope_'. $this->config['content_type'], UNIQUE_FIELD_SCOPE_TYPE); + $nid = array_shift(unique_field_match_value($target, array(array('value' => $value)), variable_get('unique_field_scope_'. $this->config['content_type'], $scope))); + } } if ($nid) { // Return with the first nid found.