4

I would like to set some values in the node before actually writing the data to the DB. I already have it working by modifying book_nodeapi but I would like to do it from outside the code, some _alter option that allows me to leave the module code untouched would be great.

Thanks

googletorp
  • 33,075
  • 15
  • 67
  • 82
German
  • 43
  • 2

2 Answers2

2

You can make a custom module and implement hook_nodeapi (mymodule_nodeapi) in it just as the book module does. Every active module gets a chance to hook into nodeapi for all nodes.

Henrik Opel
  • 19,341
  • 1
  • 48
  • 64
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • 1
    +1 - this is the most flexible way to do this - you'd need to make your changes on the `presave` operation (the insert/update operations will be triggered only *after* the node has been saved to the database) – Henrik Opel May 17 '10 at 09:56
1

If I understand what you need, Rules module can be very useful in such tasks. All you need to do is to create a condition according to the content type you want, and to have an action that sets the value. Setting the value can be done using static values, Token values, or even PHP code.

Here is a screencast with Rules basics.

Shushu
  • 774
  • 6
  • 19
  • +1 - this is a somewhat less flexible way compared to ceejayoz suggestion of using `hook_nodeapi`, but might be enough for your needs and does not require custom code in a custom module. – Henrik Opel May 17 '10 at 09:59
  • Well, true. I read "I would like to do it from outside the code" and thought you really don't want to code... – Shushu May 19 '10 at 20:38