Line 7:
Line 7:
= Implementation =
= Implementation =
−
To implement a hook in your own module (so that your module can be ''hooked'' by others), you have two steps to follow.
+
Pour implémenter un hook dans votre propre module (afin que votre module puisse être "hooké" par d'autres), vous devrez procéder à 2 étapes.
−
These steps must be followed for every php script of your module where you want to implement hooks.
+
Ces étapes doivent êtres reproduites pour chaque script php de votre module où vous voulez implémenter des hooks.
−
1- Initialize the HookManager object (put this in the beginning of your script, just after includes):
+
1- Initialiser l'object HookManager (placez ce bout de code au début de votre script php, juste après ou avant les includes):
<source lang="php">
<source lang="php">
Line 21:
Line 21:
</source>
</source>
−
$hookmanager->initHooks() takes 1 parameter (an array of contexts) and activate the hooks management for this script:
+
$hookmanager->initHooks() accepte 1 paramètre (un array de contextes) et active la prise en charge des hooks pour ce script:
- ''''context'''' is the module's context as a string. This is simply a indicator that hooking functions can use to detect which modules they want to hook (several different modules can have the same hooks names, but a hooking function may want to hook only one specific module and not the others).
- ''''context'''' is the module's context as a string. This is simply a indicator that hooking functions can use to detect which modules they want to hook (several different modules can have the same hooks names, but a hooking function may want to hook only one specific module and not the others).
Line 29:
Line 29:
−
2- Place hooks wherever you want in your script:
+
2- Placer ensuite des hooks où vous voulez dans votre script:
<source lang="php">
<source lang="php">
Line 37:
Line 37:
</source>
</source>
−
'''$hookmanager->executeHooks()''' takes 4 parameters:
+
'''$hookmanager->executeHooks()''' accepte 4 paramètres et ajoute un hook (qui est un point d'entrée dans votre script pour des fonctions externes à votre script et module):
- ''''hookname'''' is the hook's name as a string (can be anything you want, or you can follow the Dolibarr's nomenclatura, look at the list of hooks below). eg: 'formObjectOptions'
- ''''hookname'''' is the hook's name as a string (can be anything you want, or you can follow the Dolibarr's nomenclatura, look at the list of hooks below). eg: 'formObjectOptions'
Line 52:
Line 52:
- '''$action''' is a string indicating the current action (can be set to null or to something sensible like 'create' or 'edit').
- '''$action''' is a string indicating the current action (can be set to null or to something sensible like 'create' or 'edit').
−
Note: You will want to redo this step if you want to add multiple hooks at different places in your script.
+
Note: Vous devrez refaire cette étape plusieurs fois si vous voulez ajouter plusieurs hooks à différent endroits de votre script.
−
Now your module should be hookable, and you can follow the procedure below in '''Usage''' to implement a hooking function that will take advantage of your new hooks.
+
Maintenant votre module devrait pouvoir être hooké, vous pouvez suivre la procédure ci-dessous dans '''Utilisation''' pour implémenter une fonction hook qui en prendra avantage (permet aussi de tester que cela fonctionne).
−
Note2: If your hook can't be accessed, try to DISABLE then RENABLE your module for the hooks to be taken in account by Dolibarr (may not be required).
+
Note2: Si vos hooks ne fonctionnent pas, essayez de DÉSACTIVER puis RÉACTIVER votre module dans l'interface d'administration afin que les hooks soient detectés par Dolibarr (mais il n'est pas confirmé que ce soit nécessaire ici).
= Utilisation =
= Utilisation =