Hi,

I need to overwrite Hooks in my own module.

For example, i need to overwrite user_pass() (user.module) hook in my module, then I wanted to rewrite the signature of the method and it would automatically by Drupal.

Another way would be using some of the specific function of Drupal, like a:

[myown.module]

function user_pass() {
  if (exists_hook('user_pass')) {
    overwrite_hook('my_callback_function');
  }
}

function my_callback_function () {
  //my custom implementation of user_pass hook
}

Finally .. the last way would be intercepting a hook, there is this possibility?

Thanks a lot.

- MC

Comments

nevets’s picture

First the term 'hook' n Drupal is specific to functions call using module_invoke(). So the function user_pass() is not a hook, just a regular PHP function and I know of no way to override a function.

For the second part, "Finally .. the last way would be intercepting a hook, there is this possibility?", if you mean intercepting/replacing another module hook, no.

marcuscavalcanti’s picture

Tnks nevets for your attention :)

So, if I want to change the format of the Drupal reset my password or insert some logic in the method user_pass() can'tI?

nevets’s picture

Because the function user_pass() simply produces a form, there are ways to alter the form including changing the validation and submit functions. You would need a module that implements the form_alter hook and want to read up on the Forms API

marcuscavalcanti’s picture

For example, if i change user_pass_submit() function, to implements my own logic, it is possible?

nevets’s picture

Indirectly, you need a module that implements the form_alter hook for that form that changes the value of '#submit' for the function to one you provide.