7

Is there a possible to override a module's hook? What I want is, write a search__query_alter() hook to restrict search results. But to achive this, I should write the hook in built-in module search's .module file.

This way, I'm hacking into core drupal files, which must be bad. Is there a way to write the hook for another module in my theme's template.php file or somewhere else, not touching the core drupal files? When I write search_query_alter() in my theme's template.php file it simply doesn't work.

From my question, you may understand I'm very new to Drupal! Thank you for helping.

6

You must create a custom module and add a custom hook function to it. The function name will be modulename_query_alter (). Drupal maintains a list of all included hooks by searching the enabled modules for functions following that pattern.

Instructions for creating one are here. This is the basic means for introducing custom behaviors to your site. The hook system is discussed here and you should look at using the hook_query_alter function here.

This will get you started and no doubt lead to further questions.

2

You can override hooks, or use hooks to add data by creating a small custom module. Start here on how to create modules: http://drupal.org/node/361112

Basically then you add:

function MYMODULE_query_alter () {
  //put your code here
}

Where MYMODULE is the name of your custom module.

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.