dolibarr  7.0.0-beta
Public Member Functions | List of all members
HookManager Class Reference

Class to manage hooks. More...

Public Member Functions

 __construct ($db)
 Constructor. More...
 
 initHooks ($arraycontext)
 Init array $this->hooks with instantiated action controlers. More...
 
 executeHooks ($method, $parameters=array(), &$object='', &$action='')
 Execute hooks (if they were initialized) for the given method. More...
 

Detailed Description

Class to manage hooks.

Definition at line 30 of file hookmanager.class.php.

Constructor & Destructor Documentation

HookManager::__construct (   $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 54 of file hookmanager.class.php.

Member Function Documentation

HookManager::executeHooks (   $method,
  $parameters = array(),
$object = '',
$action = '' 
)

Execute hooks (if they were initialized) for the given method.

Parameters
string$methodName of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
array$parametersArray of parameters
Object$objectObject to use hooks on
string$actionAction code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
Returns
mixed For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller. For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller. All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller. $this->error or this->errors are also defined by class called by this function if error.

Definition at line 125 of file hookmanager.class.php.

References dol_syslog().

HookManager::initHooks (   $arraycontext)

Init array $this->hooks with instantiated action controlers.

First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file. This makes $conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...)) When initHooks function is called, with initHooks(list_of_contexts), an array $this->hooks is defined with instance of controler class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context). Then when a hook executeHooks('aMethod'...) is called, the method aMethod found into class will be executed.

Parameters
string[]$arraycontext Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
Returns
int Always 1

Definition at line 71 of file hookmanager.class.php.

References dol_include_once(), and dol_syslog().


The documentation for this class was generated from the following file: