• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/CustomSection/Entity/CustomSectionTable.php
  • Класс: BitrixIntranetCustomSectionEntityCustomSectionTable
  • Вызов: CustomSectionTable::fillCodeIfEmptyOrInvalid
static function fillCodeIfEmptyOrInvalid(Event $event, bool $isUpdate): EventResult
{
	$result = new EventResult();

	$fields = $event->getParameter('fields') ?? [];

	$code = isset($fields['CODE']) ? (string)$fields['CODE'] : null;
	if ($isUpdate && is_null($code))
	{
		return $result;
	}

	if (!static::getCodeGenerator()->isCodeValid((string)$code))
	{
		$newCode = static::getCodeGenerator()->generate($fields['TITLE'] ?? null);

		if (empty($newCode))
		{
			$result->addError(new EntityError('CODE value is invalid. Could not generate new one automatically'));
		}
		else
		{
			$result->modifyFields([
				'CODE' => $newCode,
			]);
		}
	}

	return $result;
}