I
I
Ivan Anikin2019-10-09 14:38:28
1C-Bitrix
Ivan Anikin, 2019-10-09 14:38:28

Why doesn't CIBlockElement::Add() throw errors on required fields?

The following code runs without error, even though 'PROPERTY_VALUES' is missing the required 'EMAIL' property. and if I try to do something similar through the admin panel where the same CIBlockElement::Add() file is processed in the \bitrix\modules\iblock\admin\iblock_element_edit.php file, it will give an error that the property is missing.

$add = new \CIBlockElement();
$data = [
            'IBLOCK_ID' => 7,
            'ACTIVE' => 'Y',
            'NAME' => date('d.m.Y H:i') ,
            'PROPERTY_VALUES' => [
               'NAME'=> 'Имя',
               'PHONE'=> '322-223-322'
           ]
        ];

     $id = $add->Add($data);
      if (!$id) {
            throw new \Exception($add->LAST_ERROR);
        }

How to force to give similar errors and not to create an element if the obligatory property did not come?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Anikin, 2019-10-09
@randomizex

Understood. In CIBlockElement::Add(), checking for properties works differently.
it only checks the validity of the passed properties in 'PROPERTY_VALUES'. That is, so that she swears that (Required property "###" is not filled). It must be given to 'PROPERTY_VALUES' with an empty value.
It also does not check the user's write permissions, they must be checked separately via \CIBlock::GetPermission().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question