In conjunction with a patch that provides http://drupal.org/node/1089632 I'd like to add functionality to allow for creating new nodes on import if they don't exist when the field type is Node Reference.
I need help knowing the best place to put settings for these imports:
For each node reference field, there are two more settings that would need to be set:
1: A select box: 'Create New Nodes' or 'Generate Error if an existing Node isn't found'
2: If the option of Create new Nodes is selected, and the node reference allows for referencing more than one node type, ask which type of node should be created.
Should these options be placed on step 5 of the Node Import screen, along with the
Or should we use some Javascript/jQuery to make these fields appear on step 4?
Are there any other needs that should be fixed along with this? I'll include the code for confirming that the valid node types are searched per http://drupal.org/node/954276 and http://drupal.org/node/514552
Comments
Comment #1
darrellduane commentedIn a nutshell I'd like to give the user a lot more ability to configure how their NodeReference fields get imported, such as:
Is the data in the flat file:
-- NIDs
-- Node Titles
-- Set to 1 for when the Column Header matches the Node Title
If a node isn't found, should a node be created?
If so, and the NodeReference field matches multiple node types, which node type should be created?
Should the comparison between the data in the CSV and the existing Node Title be done with:
--- TO_LOWER (default: yes)
--- TRIM (default: yes)
I think this is it but I may think of more, can anyone think of other needs?
Comment #2
Robrecht Jacques commentedThese options should go on the step 5 - Set import options page.
If possible, the NIDs and/or Node Titles matching should be checkboxes (so users can select them both) and be enabled by default (which is the current behaviour for nodereference fields).
I'm unsure what you mean by:
The other options are great.
Would be great if you could streamline node-references like this.
Comment #3
Robrecht Jacques commentedAh... reading your other post (http://drupal.org/node/1089632) I see now that it might make sense to do this on the mapping page as well, eg: map a column to "node reference by nid" or "node reference by title". I suppose this is how user_import currently works?
I suppose this could be done, but I prefer it to be options. So you map the Node reference field to one column (or multiple), and the options specify how to interpret it.
If you would have many node reference fields, this would mean a lot of options to select the mapping from (multiplied by 2 or 3).
So, code would need to be added to a hook_node_import_options() (or to hook_node_import_options_alter() if you want to set these options for each field with a node_reference input_format, not just fields by Node reference module).
You can contact me further here if you need further guidance.
Note that the same options (match by tid, match by title, case insensitive, create in vocabulary if not exists, ...) would be great for taxonomy terms as well.
Comment #4
Robrecht Jacques commentedOne more point: the "Set to 1..." option will not work at the moment in node_import because at the time the node gets created, you don't have access to the header row any more, only to the data *that is already mapped*.
So that would need patching/extending node_import itself, which I'm willing to help with if you really think this option is useful.
Comment #5
darrellduane commentedThanks for getting back to me.
I'm willing to make check boxes (rather than radio buttons, as I had envisioned) for the choices of using NID or Node Title to select the node to reference. I'll also do this on page 5, thanks for the guidance. Yes, the patch I provided for user import works the way you describe, but I did it that way mostly because User Import doesn't have the luxury of multiple pages for configuration the way Node Import does.
-- Set to 1 for when the Column Header matches the Node Title
I have a client that has classes that he assigns to his students. There are many classes, and we reference them by putting the class name as the title of a column in a spreadsheet, and putting a 1 in the cell if the student in the row of the spreadsheet is assigned that class. In our Drupal site, we have a Node Reference field with Unlimited number of node references, referencing our class nodes. The functionality I describe will allow the content profile node that we create for this student to reference multiple existing classes assigned to that student.
Yes, I may need your help getting access to the header title at this point in the code.
I haven't done much work with Taxonomy but hopefully the trail I clear in this will be easily adaptable to use with Taxonomy.
Comment #6
Robrecht Jacques commentedIf you can provide a patch of everything except the "Set to 1", I'll look into how we can pass the headers to the $values, so you can code that feature too.
Probably it will be so that $values['node_import_headers'] contains the array of headers...
But you'll need the way fields are mapped too... hmm... need to think.
Comment #7
darrellduane commentedCool, I'm tied up on another project at the moment but I'll likely have time to work on this early May.