0

How to create a node after one node created.

I have a node type of 'notifications'. I need to create an entry into that after my another content type('policy') created or updated.

I tried the policy_entity_insert function. Inside that I saved the 'notifications' node by the help of node_save(). But it is throwing the below error

Fatal error: Maximum function nesting level of '100' reached, aborting! in /var/www/dev/theme/includes/module.inc on line 327
2

hook_entity_insert is a drupal hook, not exactly a function. This hook is invoked every time an entity is created, it can be node of any type, user, comment or whatever.

I think issue might be because of infinite loop running because of probable use of node_save() inside the hook_entity_insert() implementation which means every time node_save() is called hook_entity_insert() will be invoked, inside which node_save() will be called again, thus creating non terminating loop.

I would say you better use hook_node_insert instead of hook_entity_insert, this will not solve the problem but would be node specific hook_implementation instead of broad entitywise.

for solution simple put a check something like inside your hook_node/entity_inert implementation.

  if($node->type == 'policy') {
    // your node save code goes here
    node_save($my_notification_node);
  }
  • 1
    +1. If the node type check is not working, you can place any arbitrary property in the $node object that you are going to save. It will be preserved during the entire node_save hooks set. – AyeshK Dec 17 '14 at 23:56
2

This is very simple with Rules

  1. Create a new rule, with react on event "After Saving New Content" then restrict by type "policy".

  2. Add action "Create new entity", then for entity type, select "node".

  3. Select content type "Notifications", add a value for title (use tokens for unique page titles), and use data selector for author.

Then either clone the rule, or add an event "After updating existing content".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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