- Модуль: lists
- Путь к файлу: ~/bitrix/modules/lists/lib/entity/element.php
- Класс: BitrixListsEntityElement
- Вызов: Element::add
public function add()
{
$this->param->checkRequiredInputParams(
[
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID",
"ELEMENT_CODE",
[
"FIELDS" => ["NAME"]
],
]
);
if ($this->param->hasErrors())
{
$this->errorCollection->add($this->param->getErrors());
return false;
}
$this->setUrlTemplate();
$this->validateFields();
$isEnabledBp = $this->isEnabledBizproc($this->params["IBLOCK_TYPE_ID"]);
$hasBpTemplatesWithAutoStart = false;
if ($isEnabledBp)
{
$hasBpTemplatesWithAutoStart = $this->hasBpTemplatesWithAutoStart(CBPDocumentEventType::Create);
}
if ($this->hasErrors())
{
return false;
}
$elementFields = $this->getElementFields($this->elementId, $this->params["FIELDS"]);
$elementObject = new CIBlockElement;
$this->elementId = $elementObject->add($elementFields, false, true, true);
if ($this->elementId)
{
if ($isEnabledBp && $hasBpTemplatesWithAutoStart)
{
$this->startBp($this->elementId, CBPDocumentEventType::Create);
}
return $this->elementId;
}
else
{
if ($elementObject->LAST_ERROR)
{
$this->errorCollection->setError(
new Error($elementObject->LAST_ERROR, self::ERROR_ADD_ELEMENT)
);
}
else
{
$this->errorCollection->setError(
new Error("Unknown error", self::ERROR_ADD_ELEMENT)
);
}
return false;
}
}