Hello.

I am using hook_node_presave in my module. How can I stop the node saving process and execute intead this some custom coode using this hook.

Thanks.

Comments

You can execute your code

You can execute your code inside your implementation of hook_node_presave:

<?php
function MYMODULE_node_presave($node){
 
// Your code here will execute
}
?>

Are you saying you don't want to save the node?

Yes. I want to check some

Yes.
I want to check some condition and execute some code WITHOUT saving the node(I will do some very customized node saving).
I have found one way to stop the saving process - to make a redirect.
But may be there is a more correct way?

There's always a lot of ways

There's always a lot of ways to do things in Drupal. I would go about it by altering the node edit form with hook_form_alter and have it submit to my own function instead of the standard:

<?php
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if (
$form_id == 'page_node_form') {
   
// I would look at what's in $form['#submit'] before just
    // overwriting it like this there might be a validation
    // function or something in there you want to keep
   
$form['#submit'] = array('MYMODULE_submission_handler');
  }
}

function
MYMODULE_submission_handler($form, &$form_state){
 
// Do my custom PHP stuff
}
?>

This way you are not trying to stop the save process which is already in progress, but you are stopping it before it starts. You'll also be dealing with just the form values and not a fully assembled node which might be easier or harder for you to work with depending.

Thank you very much! It is

Thank you very much! It is just what I need.

Sorry for writing in this

Sorry for writing in this topic again. Can I see the code of default Submit handler?

In your hook print the

In your hook print the contents of:

<?php
$form
['#submit']
?>

This will give you a list of the submit handlers on the form. Searching for those functions will show you all the code that is run by default.

Cheers

Tom

Bristol based Drupal web design
BlackLabel Web Design