Hooks are called using module_invoke() and module_invoke_all() : if you look at the code for these two functions, you can build how this works, but basically, if I add this to my module code:
// Other code $foo = module_invoke_all('foo_bar', $var1, $var2); // More code
Drupal will call every implementation of hook_foo_bar($var1, $var2) that it finds in the allowed modules. Based on this, you should see that the only thing that binds a particular hook to a particular module is a naming convention: if I call my module foo , my hook functions should start with hook_foo_ .
You don't know anything about nothing being called in *.api.php : since a module call is just a function call, the authors of the module include foo.api.php for documentation purposes only, to tell developers how to implement the hook.
For example, in the above case, foo.api.php will contain an example function, for example:
function hook_foo_bar($var1, $var2) { return $var1 + $var2; }
But as a module developer, I could implement hook_foo_bar() another way:
function mymodule_foo_bar($var1, $var2) { return $var1 - $var2; }
And when module_invoke_all() is called, Drupal creates a function using the short name of the implementation module ( mymodule ) and the hook name passed to module_invoke_all() ( foo_bar ), thereby calling the function mymodule_foo_bar() I just defined.
The system module in the kernel is a bit of everything: one task for Drupal 8 is to kill it and delegate its functionality to other modules.
user113292
source share