3

I want to know where I have to put below custom event handler code in bitrix24(self-hosted system) without changing any core file.

AddEventHandler('socialnetwork', 'OnBeforeSocNetGroupAdd', 'TestHandler');
function TestHandler(&$arFields) {
   $arFields['DESCRIPTION'] .= ' It is forbidden to use foul language!';
   if ($GLOBALS['USER']->GetID() == 2) {
      $GLOBALS['APPLICATION']->throwException('You cannot create groups.');
      return false;
   }
}
sh27
  • 51
  • 5

1 Answers1

3

If not custom module, you can put your code in two places:

  1. /bitrix/php_interface/init.php (if there is no init.php file, create it)

or

  1. If you have local folder in the root of the project, you can create file init.php in /local/php_interface/init.php
maxkrasnov
  • 284
  • 2
  • 7
  • Thanks for the answer it works fine. But when I am trying to capture below event it will not work.Can you please what I am doing wrong here AddEventHandler('voximplant', 'onCallInit',array('logCalInit'); function logCalInit(&$arFields){ file_put_contents('call-log.txt', 'test contact'); } – sh27 Oct 13 '17 at 09:21
  • try `AddEventHandler('voximplant', 'onCallInit','logCalInit'); function logCalInit(&$arFields){ file_put_contents('call-log.txt', 'test contact'); } `, you set in callback param array without classname, maybe this will help – maxkrasnov Oct 13 '17 at 11:44
  • ou, which version bitrix 24? try set event name `OnVoximplantCallInit` – maxkrasnov Oct 13 '17 at 11:48
  • Thanks for your reply but mention event not working.I am using bitrix25 17.0.10 – sh27 Oct 16 '17 at 14:39
  • strange, that new docs https://dev.1c-bitrix.ru/rest_help/scope_telephony/voximplant/events_voximplant/index.php – maxkrasnov Oct 16 '17 at 14:43
  • ou, see docs, there five params, not one: https://dev.1c-bitrix.ru/rest_help/scope_telephony/voximplant/events_voximplant/onvoximplantcallInit.php – maxkrasnov Oct 16 '17 at 14:44
  • Thank you for your response.Today I have tried following code and it works for the onCallStart event, not for the onCallEnd event do you have any idea what I am doing wrong here. AddEventHandler('voximplant', 'onCallStart',array('LogCall', 'Startcall'),101); AddEventHandler('voximplant', 'onCallEnd',array('LogCall', 'Hangupcall'),102); class LogCall { function Startcall($CALL_ID){ file_put_contents('call-log1.txt', 'call end'); } function Hangupcall($CALL_ID){ file_put_contents('call-log2.txt', 'call end'); } } ?> – sh27 Nov 10 '17 at 06:39