Drupal hook fired after node created
Asked Answered
A

2

6

When I create a node I want it to programmatically create some nodes that reference the node just created.

I though I would just need to change form_alter submit function for my form to call a custom function to create the nodes.

Examining the output $form_state I can see that the NID is Null. This would mean to me that my node is created after the submit has been fired. It makes sense. How can I call code to run after the node has been created so that I can automatically create some nodes that reference?

Adularia answered 9/9, 2010 at 8:52 Comment(0)
M
12

You want to use hook_nodeapi() and the insert handler:

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
      // $node contains the newly created node
      break;
  }
}
Misconstruction answered 9/9, 2010 at 8:59 Comment(0)
V
0

I've written a module that provides what you're looking for. You can find the details here : Post-save callback?

Variscite answered 4/6, 2014 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.