a hook is a function your module would invoke using module_invoke_all and would be used by your module to allow other modules the ability to modify your modules behavior
Thank for your response. That's correct. But how can i implement that to my custom module.
Let say i am building a custom module, with in that module i have written some functions, like check_user etc..
My question is that how can i call this function using hook_check_user() from some others module, where hook is the custom module name.
Any function can be called by any other PHP code so it sounds like you really just need to document the API your module provides. In the module that calls your function it is a good practice to declare a dependency in the .info file or if optional functionality use function_exists() to check for the existence of your function.
Please don't post duplicate threads, I've deleted the dupe. you're already getting assistance here, why would you want to waste someone else's time starting over from scratch? sheesh....
Although module_invoke_all is probably the preferred way to do it, you could also use module_implements(). I have had better luck doing it this way when I want to pass a variable by reference.
U can make your own hook in following steps :---
1st step :-
in your module in any function use module_invoke_all and pass parmeters.This function will check for all other modules how have implemented ur hook and return the data.
module_invoke_all('sitenews', $param1, $param2, $param3);
here sitenews is the name of yourmodule_sitenews($param1, $param2, $param3);
other module will implement this using theirmodulename_sitenews($param1, $param2, $param3){}
2nd step:--
define your urmodule_sitenews($param1, $param2, $param3); in your own module.This should return somthing.like hook_menu
function hook_sitenews() {
$content['report'] = array(
'#weight' => 0,
'#title' => t('Sample Title'),
'#body' => t('Sample content')
);
$content['another report'] = array(
'#weight' => 0,
'#title' => t('Another Sample Title'),
'#body' => t('More sample content')
);
return $content;
}
3rd step ---
implement in other module:-
like
user_sitenews();
4th step :-----
call module_invoke_all('sitenews', $param1, $param2, $param3); in ur module and get data from it and play with data.THis data will come from all the modules who hav implemented this hook..like mail it as newsletter
Comments
a hook is a function your
a hook is a function your module would invoke using module_invoke_all and would be used by your module to allow other modules the ability to modify your modules behavior
Re:
Thank for your response. That's correct. But how can i implement that to my custom module.
Let say i am building a custom module, with in that module i have written some functions, like check_user etc..
My question is that how can i call this function using hook_check_user() from some others module, where hook is the custom module name.
Hope i am able to clear my point to u.
Any function can be called by
Any function can be called by any other PHP code so it sounds like you really just need to document the API your module provides. In the module that calls your function it is a good practice to declare a dependency in the .info file or if optional functionality use function_exists() to check for the existence of your function.
_
Please don't post duplicate threads, I've deleted the dupe. you're already getting assistance here, why would you want to waste someone else's time starting over from scratch? sheesh....
Although module_invoke_all is
Although module_invoke_all is probably the preferred way to do it, you could also use module_implements(). I have had better luck doing it this way when I want to pass a variable by reference.
In your first module:
In Second module:
Just came across this
I just came across this, it is a nice succinct write-up: http://erikwebb.net/blog/drupal-design-patterns/hooks
how to make custom hook in custom module