Question: Can the function AddEventHandler be called several times for the same event?
Response: You can call the function AddEventHandler with the same first two parameters several times. There are very few cases when you cannot do that (only one handler per event is permitted). It is advisable to indicate the fourth parameter when re-calling the function. This parameter is responsible for handler call priority. If this parameter is not indicated, the handlers will be called following the order of their addition.
How does the event handler “know” what event it is handling?
A function is an even handler for modules. A function does not “know” which modules and which events, but it must perform different actions depending on the event that has occurred.
Question: How does the event handler “know” which event it is handling?
The solution depends on the initialization.
- AddEventHandler - add a layer.
- RegisterModuleDependences - add an argument at the registration stage.
$TO_METHOD_ARG = Array("argument"=>"OnUserDelete");
RegisterModuleDependences("main", "OnUserDelete", "forum", "CForum", "OnUserDelete", $sort, $TO_PATH, $TO_METHOD_ARG);
function Handler($arguments, &$arFields)