class HookManager (View source)

Class to manage hooks

Properties

DoliDB $db
string $error
string[] $errors
string[] $warnings
string[] $contextarray
$hooks

array<string,array<string,null|string|CommonHookActions>> Array with instantiated classes

$hooksSorted

array<string,array<string,null|string|CommonHookActions>> Array with instantiated classes sorted by hook priority

array<string, array{name: string, contexts: string[], file: string, line: string, count: int}> $hooksHistory
mixed[] $resArray
string $resPrint
int $resNbOfHooks

Methods

void
__construct(DoliDB|null $db)

Constructor

int<0, 1>
initHooks(string[] $arraycontext)

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

executeHooks(string $method, $parameters = array(), $object = null, $action = '')

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

Details

void __construct(DoliDB|null $db)

Constructor

Parameters

DoliDB|null $db

Database handler

Return Value

void

int<0, 1> initHooks(string[] $arraycontext)

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

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 controller 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 context hooks to activate. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...

Return Value

int<0, 1>

0 or 1

executeHooks(string $method, $parameters = array(), $object = null, $action = '')

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

@phpstan-template T

Parameters

string $method

Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...) @param array<string,mixed> $parameters Array of parameters @phpstan-param T $object @param null|Object|array<string,mixed>|string $object Object to use hooks on @phan-ignore-reference @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) @return int<-1,1> For 'addreplace' hooks (doActions, formConfirm, formObjectOptions, pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop/replace 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 if we want to keep standard actions, >0 uf we want to stop/replace standard actions (at least one > 0 and replacement will be done), <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 merged into this->resArray for caller. $this->error or this->errors are also defined by class called by this function if error. $this->warnings is also defined by class called by this function if warning.

$parameters
$object
$action