I've got node reference fields which refer to nodes that have numeric titles, which won't work with the current code because it will match NIDs that already exist on the site. In the existing code, if a NID is found that directly references the node, it is used; other wise, a search on a node with the title equal to the value in the CSV field is performed. I don't want the node with the NID equal to the value in the CSV to be used.
I've already solved this problem for user_import to a content_profile field with a patch that allows for three options for the format of imported data for Node Reference fields. Input data can be classified as either NID, Node Title, or when the data is equal to 1, set the Node Reference to reference the Node with the title that is equal to the title of the column. It works with both Node Reference fields that reference single and multiple valued fields, and it takes into account the issue of checking only Nodes that are the correct type for the Node Reference field. The patch is here http://drupal.org/node/633358
I'd like to move this into node_import as well. It'd be great to get some guidance about how the user interface for this should look. In the user_import version, there are three options provided for each node reference field:
// lets check and see if it is a Node Reference field. If so, provide a few options:
$key_details = explode(':',$key);
if($key_details[2] == 'nid'){
// option to set the NID value equal to the NID of the Node that has the value the spreadsheet equal to the title field of the Node.
if($fields[$key]['has_multiple']){
// if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
$field_options["$type $key:nodetitle_equals_value:multiple"] =t('CP: (!type) !key - Ref Node with title = value (M)', array('!key' => $fi\
elds[$key]['title'], '!type' => $type));
}else{
$field_options["$type $key:nodetitle_equals_value:single"] =t('CP: (!type) !key - Ref Node with title = value', array('!key' => $fields\
[$key]['title'], '!type' => $type));
}
// option to set the NID value equal to the NID for the Node with the node title as the value in the header of the spreadsheet. Only set t\
his value if the number '1' appears in the column.
if($fields[$key]['has_multiple']){
// if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
$field_options["$type $key:nodetitle_equals_header_if_1:multiple"] =t('CP: (!type) !key - Ref Node with title = header if value =1 (M)', \
array('!key' => $fields[$key]['title'], '!type' => $type));
}else{
$field_options["$type $key:nodetitle_equals_header_if_1:single"] =t('CP: (!type) !key - Ref Node with title = header if value =1', arra\
y('!key' => $fields[$key]['title'], '!type' => $type));
}
} // done if node column points to a node id
// option to set the NID value (and other value types) directly from the file (currently the only option.)
if($fields[$key]['has_multiple']){
// if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
$field_options["$type $key:direct_from_value:multiple"] =t('CP: (!type) !key (M)', array('!key' => $fields[$key]['title'], '!type' =>\
$type));
}else{
$field_options["$type $key:direct_from_value:single"] =t('CP: (!type) !key ', array('!key' => $fields[$key]['title'], '!type' =>\
$type));
}
however, perhaps this is somethign that should be set on Page 5 of the import process. Guidance?
Comments
Comment #1
Robrecht Jacques commentedI've answered this on http://drupal.org/node/1089644.
Comment #2
Robrecht Jacques commentedI'll set this as duplicate.