Answer the question
In order to leave comments, you need to log in
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;
// дальше уже неважно
}
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question