Search code examples
drupal-6drupal-node-hook

Set a custom message after saving a new node


Im trying to set a custom message that gets shown to users after they submit a new node. This message is going replace the standard '@type %title has been created.'

I've tried using hook_nodeapi with $op of 'insert' but no matter how I try and change module weights, my custom message always appears first before the core drupal message.

This wont work, as I need to call drupal_get_messages() to remove the orginal message before sending my own custom one.

This workflow is driving me insane, can anyone help point me in the right direction?

Cheers.


Solution

  • Check out the node_form_submit() function. Notice that it does a node_save($node); before drupal_set_message(t('@type %title has been created.', $t_args));.

    If you then check out node_save(), you'll see that's where the 'insert' $op gets called. So, the 'insert' operation for hook_nodeapi gets called before the message you're hoping to change gets output.

    You can find some workarounds described in this issue queue comment. You may also want to check out the Custom Submit Messages module, which is where that issue queue thread originates.

    In case it might help, in the past, I've sometimes resorted to writing a mini-module that implements hook_nodeapi, to find out just how the hooks are getting fired:

    function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
      switch ($op) {
        dpm('hook_nodeapi '. $op .' fired.');
      }
    }