I am using Drupal 7 with the Token module.
I wrote PHP code using the token field that can satisfy loading a specific node, updating some field values, and saving the node (using node functions).

When editing this node the code run again; I just want to run this code when creating this node. How can I do that?


You should use hook_node_insert in a custom module to run your code when the node is created.

function hook_node_insert($node) {
  // To include @marcvangend's comment.
  if ($node->type == 'type') {
    // Run code here only for node of type 'type'.
  // Run code here for all nodes...
  • thanks but in this way how can i run this code for specific content type? – Abdulrahman Mar 30 '12 at 12:11
  • Add an if-statement and check for $node->type. – marcvangend Mar 30 '12 at 12:19

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.