Hello,

I am doing a custom module for a commuinity website.
I would like that when an event (event module) is created, a node of my module is created too automaticly.

I know what properties I want for this module, I know what to enter in the database for it to work, but I need Drupal to know that a new node is created. I tried to add some db_query('') in the event.module file, it works the first time. but Drupal doesn't know that this node has been created, so for the next node created, he try to add it with the same nid that I gave for my cutome module node.

Does anyone knows how to create a node and let drupal know about it ?
Do I have to include a reference to my module and call the hook_form ?

Thank You.
Matthieu.

Comments

dwees’s picture

This is the hook for this. Check out the instructions for this function in at http://api.drupal.org

Dave

Matthieu’s picture

Thank you for your quick answer. Indeed it seems to be the hook that I need.

There is still something that I don't understand :
What I want happen when someone create a new event node, so I gess i have to put my code into the case 'insert' (in the $op switch).
Let's say that the nid of the brand new created event is 10.
I would like to create automaticly a new advpoll_binary node with the nid 11.

If I just insert my database query, then drupal won't know that i added a node. And next time I had any kind of node, it will take nid 11 and generate an error.
Do you know how to do it ?

An other question would be how to specifie that I want it to happen only for event nodes ?

Thank you.
Matthieu.

dwees’s picture

Take a look around for the function 'db_next_id', it does what you are after as far as the new node nid is concerned.

Also the nodeapi includes a parameter of $node. You just need to include a check for the correct type here.


if ($node->type == 'event') {
  // create your node code in here
  // ...
}

ryanhunt’s picture

Is this what I would need to do to have a node automatically created? I have a button defined that I would like to add the functionality to automatically create a new node of a different content type with the same name as that of the node the button is on.

I can't seem to see how to do this in the api instructions. any ideas?