Hi
QUESTION: To used node_import module, is there a special hook() function I must implement to make it work?
It take the following steps, and I want to know what happens between hook_form and hook_form_alter(): validate/hook_validate, and it is not calling hook_insert() that would perform the insert.
ISSUE: Preview Import step fails because hook_validate() fails because column value is blank. However, Sample Data step shows data within CSV file as OK to load.
DETAILs:
I want to import CVS raw data into my Drupal 6.x site, and I came across node_import:
http://drupal.org/project/node_import
I have created a simple content type module called Business Unit and it has two fields:
bus_unit_cust_name: textfield
bus_unit_cust_notes: textarea
I have created a CSV file with data only for bus_unit_cust_name column.
I import this file through node_import UI
Using node_import through its UI, I have experienced the following:
- Set file options (step 3 of 8): Sample Data for bus_unit_cust_name looks good
- Preview Import (step 7 of 8): Fails when hook_validate() is called.
The hook() calls made during Preview Import execution are in order as follows:
- hook_nodeapi(): prepare
- hook_form(): returns $form as follows
Array ( [bus_unit_cust_name] => Array ( [#type] => textfield ) [bus_unit_cust_notes] => Array ( [#type] => textarea ) ) - Something happens here but is not it is not calling hook_insert()
- hook_form_alter(): validate, and data fields are blank within $node as follows:
$node->bus_unit_cust_name is empty (NOT as expected because in CSV file)
$node->bus_unit_cust_notes is empty (as expect because not in CSV file) - hook_validate(): Fails because $node->bus_unit_cust_name is blank
$node value passed into hook_validate()stdClass Object ( [nid] => [vid] => [uid] => 1 [created] => 1242327878 [type] => tm_pm_bus_unit_cust [language] => [changed] => [bus_unit_cust_name] => [bus_unit_cust_notes] => // ... )Ideas on how I may resolve this issue?
Thanks
Jeff in Seattle
Comments
Comment #1
jeff00seattle commentedComment #2
infojunkieThe file hook_node_import_docs.php describes the hooks used by node_import. I recommend reading a few modules in the supported/ folder to understand what's going on. Unfortunately, the programming model is not very obvious and it took me a while to make something work.
Comment #3
Robrecht Jacques commentedNode import now submits the node form (node/add/tm_pm_bus_unit_cust or whatever your content type is called). This means that the validation is done by validating the form.
From http://drupal.org/node/463226 :
This should be added to your tm_pm_bus_unit_cust.module. As far as Node import is concerned, for textfields and textareas this should be enough as they don't need any special handling.
So why does it fails? Does the validation give any errors? Or is your custom validation (hook_validate()) failing because the expected $node->... are not set?
Note that hook_insert() will not be called until the form validates correctly.
Comment #4
Robrecht Jacques commentedIt may help if mail the custom module to me. I'll look into it then.