I'm trying to programmatically create child nodes according to a parent node's field value.

When a node is created, a reference to these child nodes is saved in the parent node, although the references should not be editable and visible in the edit form and when the node is viewed.

How can I implement this?

1 Answer 1


Your main problem here is you won't be able to create a reference to the created node in a form submit as the node id hasn't been created yet. I'm not actually sure at what point it becomes available in the node process either. hook_node_save is still too early and it's the last node specific hook you can do this with.

I would skip trying to do this programmatically and use rules and entity reference field. Have your rule fire after a new node is saved. then have it create a new entity (node) and set data value (entity_reference) to the newly created node. much easier to maintain than code.

  • I can't use Rules directly because the field and content type are created in my own module
    – alivenets
    Commented Jul 15, 2013 at 4:52

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.