Views: 8854
Last Modified: 12.09.2014

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.

  1. AddEventHandler - add a layer.
    function OnAdd()
    {
          RealHandler("add");
    }
    
    function OnUpdate()
    {
          RealHandler("update");
    }
  2. 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)
    {
       // code
    }



Courses developed by Bitrix24