• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/numerator/numerator.php
  • Класс: BitrixMainNumeratorNumerator
  • Вызов: Numerator::validate
private function validate($numeratorConfig)
{
	$result = new Result();
	if (!isset($numeratorConfig[static::getType()]))
	{
		$result->addError(new Error('Numerator config is required'));
	}
	$numeratorBaseConfig = $numeratorConfig[static::getType()];

	if (isset($numeratorBaseConfig['code']))
	{
		if (is_string($numeratorBaseConfig['code']) && !empty($numeratorBaseConfig['code']))
		{
			$idWithSameCode = NumeratorTable::getIdByCode($numeratorBaseConfig['code']);
			if ($idWithSameCode !== null)
			{
				$id = (int)($numeratorBaseConfig['idFromDb'] ?? null);
				if ($id <= 0 || $idWithSameCode !== $id)
				{
					$result->addError(new Error('Another numerator with same code already exists'));
				}
			}
		}
		elseif (is_string($numeratorBaseConfig['code']))
		{
			$result->addError(new Error('Numerator code should be a non-empty string, if it is provided'));
		}
		else
		{
			$result->addError(new Error('Numerator code should be a string'));
		}
	}
	if (!(isset($numeratorBaseConfig['name']) && $numeratorBaseConfig['name']))
	{
		$result->addError(new Error(Loc::getMessage('NUMERATOR_VALIDATE_NAME_IS_REQUIRED')));
	}
	$resultTemplate = $this->validateTemplate($numeratorBaseConfig['template']);
	if ($resultTemplate->getErrors())
	{
		$result->addErrors($resultTemplate->getErrors());
	}

	return $result;
}