2

I've created my own search engine with a custom module and some XML. I would like to add content to the XML file with a custom function in my module.

The content that needs to be added will be coming from some content types. Is there a way to trigger a function after a content type is saved (node saved)?

I know the Rules module can do this, but I need to do it from my custom module (i.e. I need to write a function to achieve this).

Is this even possible?

1

There are some hooks you can use to do this, but they are all fired before the data is recorded in the database.

Have a look at hook_node_insert(), hook_node_update() and hook_node_presave(). The two first ones are fired only on insert or update, the last one every time.

After, another way to do so, is to add your own submit method on node_form, using the hook_form_FORM_ID_alter() (hook_form_node_form_alter()), which will be fired after the node is properly saved in the database.

If I were you, I would use a setting page for my module to set the content types to use.

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.