Hooks system: Difference between revisions

Jump to navigation Jump to search
m
Tag: 2017 source edit
Tag: 2017 source edit
Line 97: Line 97:
One the descriptor is created, two further steps are required:
One the descriptor is created, two further steps are required:


1- add your module/the core module context name to the list of contexts you want to hook on.
1- add your context key to the list of contexts you want to hook on.
This means that when the core program code executes a context, your module hook function will be called.
This means that when the core program code is executed into a context, your module hook function will be called.
Edit your '''/htdocs/''yourmodulename''/core/modules/mod''YourModuleName''.class.php''' and add the context name to the variable '''$this->module_parts'''.
Edit your '''/htdocs/''yourmodulename''/core/modules/mod''YourModuleName''.class.php''' and add the context name to the variable '''$this->module_parts'''.
eg:
eg:
Line 109: Line 109:
Don't forget to change YourModuleName to your own module's name!
Don't forget to change YourModuleName to your own module's name!


Note: one way to determine the context name of the core module that you wish to modify is by adding this code in that modules php code:
Note: one way to determine the name of contexts you are when you reach a part of code is to add this code in the PHP code:
print('Module context: '.$object->context);
print('Module context: '.join(',', $object->contextarray));
 
Note that the '''all''' context means you want your hook beeing executed whatever is the context. The '''main''' means you want your hook to be executed for any web page, and '''cli''' means in every Command Line script (even if you can't see this context keys in $object->contextarray).


[[File:warning.png]] Note that when you add a new context name to the 'hooks' => array, this list of contexts must be stored in the database. This only occurs when the custom module is enabled.
[[File:warning.png]] Note that when you add a new context name to the 'hooks' => array, this list of contexts must be stored in the database. This only occurs when the custom module is enabled.

Navigation menu