Views: 4947
Last Modified: 28.05.2021

Event system has been changed for the core D7. Requirements for data belonging to a code triggering the event are leveled down. An example of an event sending:

$event = new Bitrix\Main\Event("main", "OnPageStart");
$event->send();

If necessary, for a sending party there is a possibility to receive the result of an event handled by accepting parties.

foreach ($event->getResults() as $eventResult)
{
    switch($eventResult->getType())
    {
        case \Bitrix\Main\EventResult::ERROR:
            // error handling
            break;
        case \Bitrix\Main\EventResult::SUCCESS:
            // successful 
            $handlerRes = $eventResult->getParameters(); // getting the result, returned by the event handler
            break;
        case \Bitrix\Main\EventResult::UNDEFINED:
            /* the handler returned undefined result instead of a \Bitrix\Main\EventResult class object 
            its result is still available via getParameters
            */
            break;
    }
}

In order to reduce the code quantity Bitrix\Main\Event class successors may be created for specific event types. For example, Bitrix\Main\Entity\Event makes it more convenient to send events connected with the modification of entities.




Courses developed by Bitrix24