0

I am sure this question has come up before, but right now my google skills are failing me. I am trying to create a migration module since I haven't had any luck with either the migrate module or migrate_d2d. Right now I am trying to populate a content type with the data from my field remap, but I can't find out how to do it.

would a simple db_insert work or is there something special I need to do to generate the field data?

1

1 Answer 1

0

Matt,

To create a node programmatically,

  1. You firstly need to create a content type for same. This will make sure that Drupal architecture is followed to create a node.
  2. Now you need to create a node from UI, and in hook_node_presave, make sure you print the node object - dprint_r($node); die; and see what is the Object architecture like.
  3. Now you need too create the same object before saving it.
  4. To, create the object, create $node = new stdClass();, define the node type $node->type = 'YOUR CONTENT TYPE NAME' and do a node_object_prepare($node), this will make sure that all the basic settings are added to the node object.
  5. Post this, make sure you create the object, same as it was in node presave stage.
  6. Just before calling node_save, call node_submit, which will prepare the node for submission.

Hope this helps !!!

2
  • Hi Vaibhav, thanks for the help. though for some reason it still isn't working. I am creating the node exactly as the original node is structured, i'm even running an array_udiff_assoc comparing both the keys and data types of the 2 arrays. then double checking with an array_diff_assoc. on node_save however, only the node is getting populated, the content_type tables are not.
    – matt
    Commented Nov 20, 2013 at 21:53
  • Also, the node type is getting set as "node", this is probably the problem, however once I run node_object_prepare changing the $object->type causes errors all over the place.
    – matt
    Commented Nov 20, 2013 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.