• Модуль: lists
  • Путь к файлу: ~/bitrix/modules/lists/lib/entity/field.php
  • Класс: BitrixListsEntityField
  • Вызов: Field::add
public function add()
{
	$this->param->checkRequiredInputParams(["IBLOCK_CODE", "IBLOCK_ID", ["FIELDS" => ["NAME", "TYPE"]]]);
	if ($this->param->hasErrors())
	{
		$this->errorCollection->add($this->param->getErrors());
		return false;
	}

	$fields = $this->getFields();
	$this->validateFields($fields);
	if ($this->hasErrors())
	{
		return false;
	}

	$object = new CList($this->iblockId);

	if (!$object->is_field($fields["TYPE"]))
	{
		if (!empty($fields["CODE"]))
		{
			$property = $this->getProperty($this->iblockId, $fields["CODE"]);
			if (!empty($property) && is_array($property))
			{
				$this->errorCollection->setError(new Error("Property already exists", self::ERROR_SAVE_FIELD));
				return false;
			}
		}
		else
		{
			$this->errorCollection->setError(new Error("Please fill the code fields", self::ERROR_SAVE_FIELD));
		}
	}

	$result = $object->addField($fields);

	if ($result)
	{
		global $CACHE_MANAGER;
		$CACHE_MANAGER->clearByTag("lists_list_".$this->iblockId);
		return $result;
	}
	else
	{
		$this->errorCollection->setError(new Error("Error saving the field", self::ERROR_SAVE_FIELD));
		return false;
	}
}