开发者

How do I update a node (book or Page) before saving it without touching the module code in Drupal?

开发者 https://www.devze.com 2022-12-31 11:32 出处:网络
I would like to set some values开发者_StackOverflow 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 t

I would like to set some values开发者_StackOverflow 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消