Answer the question
In order to leave comments, you need to log in
Problem with registerEventHandler?
I am writing my module. Register an event handler:
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->registerEventHandler(
"iblock",
"OnAfterIBlockElementUpdate",
$this->MODULE_ID,
'\foo_spammer\events\SpammerIBlockElementUpdateHandler',
"run"
);
class SpammerIBlockElementUpdateHandler
{
public function run(Bitrix\Main\Entity\Event $event)
{
return true;
}
}
Answer the question
In order to leave comments, you need to log in
The called function must be static. Did it like this:
class SpammerIBlockElementUpdateHandler
{
public static function runStatic(&$fields)
{
$self = new self();
return $self->run($fields);
}
public function run(&$arFields)
{
//some code
}
}
/*****************************/
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->registerEventHandlerCompatible(
"iblock",
"OnAfterIBlockElementUpdate",
$this->MODULE_ID,
'\foo_spammer\events\SpammerIBlockElementUpdateHandler',
"runStatic"
);
You are using the old property (there are no new infoblocks yet).
Accordingly, you need to:
1) Execute registerEventHandlerCompatible
2) Use the code from the documentation and catch not an Event, but a reference to an arraypublic function run( &$arFields )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question