How can we create multiple nodes using a single module?

It is urgent.
Thank in advance.

Comments

chx’s picture

Story module is not even 100 lines and implements 7 hooks. Replace story_ with hook_ and use drupaldocs.org for each.

Unfriendly response posted because of the "it is urgent" phrase.
--
My developer blog. | The news is Now Public | Ask not what Drupal can do for you -- ask what you can do for Drupal.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

papermonster’s picture

I might be mistaken but I think he is asking whether he can create a single module that allows the users to post different types of node within it... and yes it's possible.

First of all use hook_node_types() to define what node types the module contains.

Then for all the other node hooks (insert, update, delete, form etc) remember that $node is always passed as an argument. So to check what the node type is use $node->type

function hook_node_types() {
  return array('project-issue', 'project-project');
} 

function hook_insert($node) {
  switch($node->type) {
    case 'project-issue':
      db_query("INSERT INTO {mytable} (nid, extra)
      VALUES (%d, '%s')", $node->nid, $node->extra);
      break;
    
    case 'project-project':
      db_query("INSERT INTO {mytable} (nid, extra)
      VALUES (%d, '%s')", $node->nid, $node->extra);
      break;

  }
}

Hope this helps.

jadams’s picture

The original poster might have been ungrateful enough to not respond to your answer to his urgent question but it's exactly what I was looking for so thank you very much :)