I understand how to use hooks (
mymodule_HOOKNAME()) but what are functions used for that actually start with hook?
When I am creating custom hooks I normally just use:
First off, there's not a single function in Drupal, that starts with
Whenever you see a function name starting with
hook_, it is a symbolic name for a hook function to be implemented by a module or a theme, where
hook_ will be replaced with the module's or theme's actual name.
Within your module, all functions you want to expose to the Drupal's hook system to be called at appropriate times, will start with
mymodule_ as long as the name of your module is actually
mymodule. That is also the
MODULE part in
On the other hand,
mymodule_HOOKNAME() refers to all or any hook functions implemented by module
All modules that wish to configure custom actions will have to implement a function which starts with the module name and ends in
_action_info. Again, that's the
HOOK_NAME part in
module_invoke('MODULE', 'HOOK_NAME') just puts these two concepts (module name and hook name) together to build a specific module's hook function name, check if it exists at all and then call it.
To work out the function name to call,
module_invoke puts together the
HOOK_NAME parts, separated by an underscore. And that is why
hook_action_info() defines a function
From the Drupal 7 API:
Allow modules to interact with the Drupal core.
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.
To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.
The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name in the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().
The example functions included are not part of the Drupal core, they are just models that you can modify. Only the hooks implemented within modules are executed when running Drupal.