• Модуль: lists
  • Путь к файлу: ~/bitrix/modules/lists/lib/rest/restservice.php
  • Класс: BitrixListsRestRestService
  • Вызов: RestService::addElement
static function addElement(array $params, $n, CRestServer $server)
{
	$param = new Param($params);
	$params = $param->getParams();

	$iblock = new Iblock($param);
	if (!$iblock->isExist())
	{
		self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
	}

	global $USER;
	$rightParam = new RightParam($param);
	$rightParam->setUser($USER);
	$rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);

	if (!CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
	{
		throw new AccessException('Available only on extended plans');
	}

	$elementRight = new ElementRight($rightParam);
	$right = new Right($rightParam, $elementRight);
	$right->checkPermission(ElementRight::ADD);
	if ($right->hasErrors())
	{
		self::throwError($right->getErrors());
	}

	$element = new Element($param);
	if ($element->isExist())
	{
		self::throwError($element->getErrors(), "Element already exists", Element::ERROR_ELEMENT_ALREADY_EXISTS);
	}

	$elementId = $element->add();
	if ($element->hasErrors())
	{
		self::throwError($element->getErrors());
	}

	return $elementId;
}