Views: 3319
Last Modified: 04.06.2024

Events

You can use standard ORM mechanisms to subscribe to iblock entity events:

use Bitrix\Main\ORM\Data\DataManager;
		
// iblock ID
$iblockId = 32;

// iblock object
$iblock = \Bitrix\Iblock\Iblock::wakeUp($iblockId);

// event manager
$em = \Bitrix\Main\ORM\EventManager::getInstance();

$em->registerEventHandler(
    $iblock->getEntityDataClass(),
    DataManager::EVENT_ON_BEFORE_ADD,
    'mymodule',
    'MyClass',
    'method'
);

Attention! At this moment, events for legacy kernel iblocks are not supported.

Custom property types

You need to set an individual callback GetORMFields to add your own fields to entity when describing the property:

public static function GetUserTypeDescription()
{
    return [
        ...
        "GetORMFields" => array(__CLASS__, "GetORMFields"),
    ];
}

/**
 * @param \Bitrix\Main\ORM\Entity $valueEntity
 * @param \Bitrix\Iblock\Property $property
 */
public static function GetORMFields($valueEntity, $property)
{
    $valueEntity->addField(
        ...
    );
}


Courses developed by Bitrix24