• Getting Started

Using Hooks

Hooks provide a way to extend your modules to allow other modules to ‘hook in’ at certain points.

Take for example a calendar app built on Includable. It has a hook that is called calendar-schedule. This allows other modules to display a schedule window next to the task list in the module.

Important to note is that hooks are one-way only, in the sense that they are only called at a certain moment. For a more extensible way of data transport, take a look at Imports, a way to use data shared by a single module in other modules.

Hooking into a module

To extend a module, you need to know which hooks exist in the module. We are currently working on a list of hooks per module.

A hook is simply a controller value, so you need to add it to your module.json:


   "controllers": {
      "courses-before-list": "hooks/courses-before-list.php"

It depends on the module how the hook code itself might look, usually you simply change some of the variables in $this (the Container object) or you output your data.

Adding a hook to your module

Adding a hook can be done with $this->hook_call():



// In the courses module, this would look for controllers with the name 'courses-before-list':
$hooked = $this->hook_call('before-list');

// $hooked contains the number of hooks that were called:
   echo 'Wow, ' . $hooked . ' modules hooked into this!';
   echo 'Nope, no matching modules...';

Note about hook loading order

The order of hook execution is deterministic, as it is decided by the module ID of the hook module, which is sorted in ascending order.