439
edits
(ajout de Implementation (non traduit, en anglais) et liste contextes) |
(→Implementation: traduction partielle en francais) |
||
| Line 7: | Line 7: | ||
= Implementation = | = Implementation = | ||
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. | |||
Ces étapes doivent êtres reproduites pour chaque script php de votre module où vous voulez implémenter des hooks. | |||
1- | 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() | $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- | 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()''' | '''$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: | Note: Vous devrez refaire cette étape plusieurs fois si vous voulez ajouter plusieurs hooks à différent endroits de votre script. | ||
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: | 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 = | ||
edits