Views: 2803
Last Modified: 30.03.2022

Each iblock is an independent data type with its own set of properties. It's represented by a separate entity in the ORM:

Entity class name includes a new field value taken from API symbolic code iblock config. This code ensures the class unique status independently from ID and environment.

Important! You need to set API symbolic code (API_CODE field) for specific block to start using ORM. It's a string with a symbol from 1 to 50, starting from a letter and consisting of Latin characters and numerals.

Property contains not just scalar values, but also relations with individual mini-entities having two key fields: VALUE and DESCRIPTION. Singular properties are presented in the iblock element by the field Reference, multiple properties - OneToMany:

You can add extra fields to entities of some property types. For example, link to a bound iblock element:

More details on basic property types

You can find direction among a large number of properties using annotations mechanism Majority of Object and Collection methods - are virtual, processed via magic__call. At the same time, they are designed for the intuitively clear and self-explanatory named methods and without autocomplete in IDE their value significantly decreases.
For the IDE to know about their existence and to help find direction in the large number of classes and methods, Bitrix24 have provided a special service file with annotations for all entities.

Learn more ...
. All iblocks will be described as ORM entities when indexing the iblock module. You need to clearly designate iblock class to get hints in the code:

// connecting iblock module
\Bitrix\Main\Loader::includeModule('iblock');

// input data
$iblockId = 32;
$iblockElementId = 678;

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

// element object
/** @var \Bitrix\Iblock\Elements\EO_ElementLink $element */
$element = $iblock->getEntityDataClass()::getByPrimary($iblockElementId)
    ->fetchObject();

// getting SOME_STRING property
$element->getSomeString();

Class autoloading automatically triggers the call getEntityDataClass(), i. e. you won't have to pre-compile iblock entity.

If you want to use IDE hints on iblock element type checking, you need to directly set its class by annotation type:

  • for element;
    /** @var \Bitrix\Iblock\Elements\EO_ElementLink $element */
    
  • for collection,
    /** @var \Bitrix\Iblock\Elements\EO_ElementLink_Collection $element */
    
where Link in the class name - iblock API symbolic code.
Attention! Property's symbolic code shall not match with element field name in an iblock. Otherwise, you won't be able to work with property by name (symbolic code) in ORM.



Courses developed by Bitrix24