📜 ⬆️ ⬇️

Highload information blocks and work with them

Good day.

Today we will talk about Highload information blocks. More precisely how to work with them. If you look on the Internet, there is always a way to get information from them, but how to write it down, change it, delete it — I didn’t find it (I’d probably just been looking bad), but I really had to.
Therefore, I turned to LayfAPI and unearthed something. Let's start in order.
As you probably noticed, these information blocks contain custom fields. Those. each field starts with a UF. But I will not chew, tk. Who kodit on bitrix, he knows it.


Before any actions you need to connect the necessary module:
CModule::IncludeModule("highloadblock"); 

')
Then comes the fun part.

Make the connection settings:

 use Bitrix\Highloadblock as HL; use Bitrix\Main\Entity; 


This is a kind of symbolic links (who worked with multisite will understand). For the rest, connect not in functions, not in conditions, etc. (You can connect in the components and result_modifier.php).

It needs to be connected up to all conditions, it does not work in connecting the function, etc.

Next, you need to write the following code (select the required fields and enable the functions of the classes):

 $hlbl = 1; - "ID Highload " (      ). $hlblock = HL\HighloadBlockTable::getById($hlbl)->fetch(); // get entity $entity = HL\HighloadBlockTable::compileEntity($hlblock); $entity_data_class = $entity->getDataClass(); 


Then we can work directly with the Highload infoblock:

Adding data:
for adding data it is responsible, as always, for their function:
 $result = $entity_data_class::add($data); 

To clarify here I think it does not cost much: class-function.
The fact is that we do not know how exactly fields are given to the $ data array. I will explain. This is, as we have already seen “User fields”, and the field code is transmitted (UF _ *******).
those.
 data = array( "UF_DATE_FROM"=>'$datefrom', "UF_DATE_TO"=>'$dateto', ); 


Well, after that we add already higher function.

This is to select the ID after the addition (in case you need to check whether the addition occurred).
 $ID = $result->getId(); 


Deletion of data:

to delete data you just need to know the ID of the element. Everything is simple as usual:
 $entity_data_class::Delete($ID); 


Change data:

 $result = $entity_data_class::update($ID, $data); 

Feature:
change (you can pass only one parameter that needs to be changed). Those. you can pass only one property, and it will change. For simple information blocks, a separate function is used for this.
Well, $ ID is the ID of the Highload element of the information block.

PS:
To change a custom property of type Y / N, we must give Y / 0, rather than Y / N as usual. (this is my experience).

You will find a selection of data from these information blocks in the components:
highloadblock.list
highloadblock.view


If there is time - I will write about one bitrix function, which selects commercial offers with prices and all their functionality by the array of elements. (Although you can see through live api).

Article written for review. If someone knows more - write in the comments.

With SW., Coder.

Source: https://habr.com/ru/post/207700/


All Articles