D
D
den-masonov2017-06-06 10:22:23
1C-Bitrix
den-masonov, 2017-06-06 10:22:23

After changing the character code in the OnBeforeIBlockElementAdd event handler, the character code is not checked for uniqueness. Where to dig?

AddEventHandler("iblock", "OnBeforeIBlockElementAdd", Array("CustomFields", "OnBeforeIBlockElementAddHandler"));
class CustomFields
{ 
// создаем обработчик события "OnBeforeIBlockElementAdd" 
  function OnBeforeIBlockElementAddHandler(&$arFields) 
  {
      $arFields["CODE"] = $arFields["CODE"]."_".date('dmY'); 
      return;
  }
}

Here is the actual code from the Bitrix docks. Everything changes and is saved as needed, only the validator does not work now

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Georgy Bondarenko, 2017-06-06
@den-masonov

That's right, checking the symbolic code of an infoblock element occurs before the OnBeforeIBlockElementAdd or OnBeforeIBlockElementUpdate events. This happens in bitrix/modules/iblock/classes/general/iblockelement.php (from lines 4128 to 4149)
If you want to change the character code to, then use the OnStartIBlockElementAdd event)

M
Maxim Pavlov, 2017-06-06
@Ifelseapps

I suspect that you will have to do the validation in the handler by hand.

// делаем выборку элементов по новому символьному коду
// ...
if (//что-то нашлось) {
   $APPLICATION->ThrowException('Элемент с таким символьным кодом уже существует');
   return false;
}

If you want to understand how Bitrix itself checks for uniqueness, then open the Network tab in the browser and click on the "Apply" button in the admin panel, see which file processes the Ajax request, and then see what actions are performed there.

D
DeclanBartowski, 2017-06-06
@DeclanBartowski

And in setting up the infoblock, is it necessary to check for uniqueness?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question