Bitrix — ORM events according to D7

Vitalii Sestrenskyi
1 min readFeb 24, 2018

--

In this short note I wanna tell about events system in Bitrix Framework. With new core D7 developers have opportunity to use typically events such as:

OnBeforeAdd, OnAdd, OnAfterAdd,

OnBeforeUpdate, OnUpdate, OnAfterUpdate

OnBeforeDelete, OnDelete, OnAfterDelete

It’s really great because we don’t need to go to documentation each times and find necessary events. In this situation we definitely know that we have this event. But we have to remember that not every tables in Bitrix have ORM class. If we don’t have it we can’t use this functionality.

So let’s see example. We have class \Bitrix\Sale\Internals\DiscountTable in sale module which described in file \bitrix\modules\sale\lib\internals\discount.php . This class extends from \Main\Entity\DataManager so it’s our ORM class with events which I’ve written above. Let’s create the event handler.

<?php
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
'sale',
'\Bitrix\Sale\Internals\Discount::OnBeforeAdd',
function (\Bitrix\Main\Event $e)
{
// your code
$e->getParameters();
}
);

This example works great but we have a little strange moment it’s — Table. We must remember about it. In \bitrix\modules\sale\lib\internals\discount.php we can see class name DiscountTable but in addEventHandler we must write just Discount.

--

--