1

Where can I hook into drupal to modify the value of a specific field just before it is inserted into the database?

For example, lets say I wanted to trigger an email or run an arbitrary piece of code just before the node is inserted into the database?

I've been looking at hook_node_presave and it looks like it will do what I want, but I need it to only apply to one content type.

1 Answer 1

1

You can probably use either hook_entity_presave(), hook_node_presave() hook_field_attach_presave(). These hooks are all pretty similar right now. Actually not sure why there are 3 of them :)

Simply add a check for the content type and/or the existense of the field you want to alter.

2
  • Thank you, that was exactly what I was looking for. For searchers: function hook_node_presave($node) { if ($node->type == 'node_machine_name' && $node->is_new === TRUE) { //Logic Here } }
    – Citricguy
    Jul 13, 2011 at 1:29
  • Looks good, feel free to edit that directly into my answser (yeah, you can do that, someone with more points just needs to approve it afterwards). That's much more readable than in a comment.
    – Berdir
    Jul 13, 2011 at 1:35

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.