Views: 292
Last Modified: 28.03.2022

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, active iblock events support is not available.

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