07-24-2023, 09:23 AM
Is it possible to create **your own** hook in a Drupal module for other Drupal modules to consume? If not, is there a mechanism in Drupal for third party developers to provide hooks? If everything's been a no so far, where in the core are the list of hooks implemented?
As I understand things, Drupal modules work on a event like system called <a href="http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7">hooks</a>. When you create a new module, you create functions that implement a hook. For example, there's a <code>hook_delete</code> hook. If you implement a function in your module
function mymodule_delete($node)
{
}
this function will be called whenever a node is deleted.
What I want to know is, is there a way or me, as a third party module developer, to create **my own** hooks. Say, something like <code>hook_alanskickbutthook</code> so that other module developers could subscribe to this hook.
If this is possible, how do you do it? I've looked around the official docs and haven't found much there, and I still get a little dizzy when I start poking around the Drupal source code (I understand recursion, but don't spend enough time thinking about recursive problems). Full solutions are welcome, but I'm happy to just be pointed in the right direction.
As I understand things, Drupal modules work on a event like system called <a href="http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7">hooks</a>. When you create a new module, you create functions that implement a hook. For example, there's a <code>hook_delete</code> hook. If you implement a function in your module
function mymodule_delete($node)
{
}
this function will be called whenever a node is deleted.
What I want to know is, is there a way or me, as a third party module developer, to create **my own** hooks. Say, something like <code>hook_alanskickbutthook</code> so that other module developers could subscribe to this hook.
If this is possible, how do you do it? I've looked around the official docs and haven't found much there, and I still get a little dizzy when I start poking around the Drupal source code (I understand recursion, but don't spend enough time thinking about recursive problems). Full solutions are welcome, but I'm happy to just be pointed in the right direction.