Drupal - Create a hook function
Essentially there are 2 things needed to create your own hook(s).
- Create your own function that calls
module_invoke_all('WHAT_YOU_WANT_YOUR_HOOK_TO_BE_CALLED');
- Create your new module and a function called
YOURMODULE_WHAT_YOU_WANT_YOUR_HOOK_TO_BE_CALLED()
That is ALL it actually takes to implement your own hooks in a Drupal module. The great thing here is the flexibility that it provides for you to do anything, AND allow other developers to easily extend your work. The major consideration I can see here is naming your hook. You should obviously try to choose something unique to your module, that a core or another contributed module wont be using.
You don't create a hook, in the same way Drupal core doesn't create hook_nodeapi()
, or hook_hook_info()
. You write code that uses (invokes) the implementation of a hook done in other modules. The modules that want to interact/integrate with yours will implement that hook, and your module will use module_invoke()
, module_invoke_all()
, or drupal_alter()
to invoke those hooks.
The correct phrase is not creating a hook, but defining a hook, which is essentially documenting that your module invokes a specific hook.