Documentation

OnAfterIBlockElementAdd

event handler(
 array &arFields
);
The event OnAfterIBlockElementAdd is called after adding new iblock element by the method CIBlockElement:Add. Operates independently from directly created/modified elements, that's why the parameter RESULT_MESSAGE must be checked additionally.

Parameters

ParameterDescription
arFields The new information block element array of fields.

The additional entry "RESULT" contains the value returned by the CIBlockElement:Add method. If an error occurred during the method execution, the entry "RESULT_MESSAGE" contains the error description.

Note
The parameter(s) of this handler are references to the original variables. Hence, altering their values from within the handler causes changing values of the source variables passed to the handler.

Notes:
  • The event OnAfterIBlockElementAdd will be called in any case, even if OnBeforeIBlockElementAdd has triggered an exception and an element was not added. You can find out the adding event was cancelled via the event OnAfterIBlockElementAdd in arFields["RESULT"]. When the adding was successful, it will store the element ID. Otherwise - false.
  • When a details or preview image was uploaded, the arFields["PREVIEW_PICTURE"] (arFields["DETAIL_PICTURE"]) stores the original temporary file (from temp folder) in the format:
    (
                [name] => 3323207.jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpAU0r3o
                [error] => 0
                [size] => 577894
                [del] => 
                [description] => 
                [MODULE_ID] => iblock
            ) 
    
    As the same time, the actual file that is bound to the element is not specified. Simultaneously, the "PREVIEW_PICTURE_ID" ("DETAIL_PICTURE") key (storing the ID of the file that is attached to the element) is passed to the array arFields.

See Also

  • OnBeforeIBlockElementAdd event
  • CIBlockElement:Add
  • Event handling

    Function example

    <?
    // файл /bitrix/php_interface/init.php
    // register the handler
    AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("MyClass", "OnAfterIBlockElementAddHandler"));
    class MyClass { // create the event handler "OnAfterIBlockElementAdd" public static function OnAfterIBlockElementAddHandler(&$arFields) { if($arFields["ID"]>0) AddMessage2Log("entry with code ".$arFields["ID"]." is added."); else AddMessage2Log("Error adding entries (".$arFields["RESULT_MESSAGE"].")."); } } ?>

  • © «Bitrix24», 2001-2024
    Up