0

I use this solution for now which works great: It's with Computed fields, and I use this line: $entity_field[0]['value'] = ip_address();

So basically what it does, it's when a user submits a new node, it also attach his IP address to the node, which is great.

The problem is that if another user decides to edit the node, the IP field is being updated with the editors IP. Which is bad.

The IP should be printed only of the author of the node. And no matter how many other IPs edits the node, those should be ignored.

So, I was thinking maybe there was possible to do this by editing the PHP line or am I looking in wrong direction?

2 Answers 2

1

Another option is to use Rules on new content creation then run the php code.

The Rules module allows site administrators to define conditionally executed actions based on occurring events (known as reactive or ECA rules). It's a replacement with more features for the trigger module in core and the successor of the Drupal 5 workflow-ng module.

EDIT:

  • Enable the module 'PHP Filter'
  • In Rules, use the 'After Saving New Content' React on Type - this will trigger each time content is published for the first time
  • Optionally, add a condition Restrict by Type, choose the content type in which you want this to appear
  • Add a new action 'PHP: Execute custom php code' with your own code
0
0

Use the hook_node_insert, it respond to creation of a new node, not when you edit it.

function YOURMODULENAME_node_insert($node) {
  if ($node->type == 'nodetype') {
    // Action
  }
}

Greetings.

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.