J
J
JohnDaniels2015-08-26 12:32:01
1C-Bitrix
JohnDaniels, 2015-08-26 12:32:01

How to get announcement image in OnAfterIBlockElementAdd?

Situation: when adding news, you need to create a letter and send it to certain users.
I did it using OnAfterIBlockElementAdd, everything works, but
I can't extract the announcement picture from the news (to insert it into the letter).
if done

AddEventHandler("iblock", "OnAfterIBlockElementAdd", "OnAfterIBlockElementAddHandler");

function OnAfterIBlockElementAddHandler(&$arFields)
{
    if(!$arFields["RESULT"])
        return false;

    if($arFields['IBLOCK_ID'] == 5){ //инфоблок новостей
        var_dump($arFields);die;

// дальше уже неважно
}

then there is no "PREVIEW_PICTURE" field in $arFields.
there is a picture in the news.
the documentation says that "arFields["PREVIEW_PICTURE"] (arFields["DETAIL_PICTURE"]) stores the initial temporary file (from the temp folder)" and "At the same time, the real file that is attached to the element is not specified. At the same time the key "PREVIEW_PICTURE_ID" ("DETAIL_PICTURE") is passed to the arFields array, it stores the ID of the file attached to the element. "
I simply don't have such keys.
Has anyone come across?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Maksimenko, 2015-08-27
@olegprof

You have an array $arFields which contains the ID key - the ID of the infoblock element. Getting PREVIEW_PICTURE based on this is not a problem.

A
Alexey Lobanov, 2015-08-29
@atlant2010

AddEventHandler("iblock", "OnAfterIBlockElementAdd", "OnAfterIBlockElementAddHandler");
function OnAfterIBlockElementAddHandler(&$arFields) { 
    if(!$arFields["RESULT"]) return false; 
    If($arFields['IBLOCK_ID'] == 5) { //инфоблок новостей 
        $res = CIBlockElement::GetByID($arFields['ID'] ); 
        if($ar_res = $res->GetNext()) {
            $rsFile = CFile::GetFileArray($ar_res["PREVIEW_PICTURE"]);
            // $rsFile["SRC"] - относительный путь к картинки относительно DOCUMENT_ROOT
        }
 // дальше уже неважно
 }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question