• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_field_multi.php
  • Класс: \CCrmFieldMulti
  • Вызов: CCrmFieldMulti::fetchCountryCode
static function fetchCountryCode(string $typeId, array $input): string
{
	if ($typeId !== static::PHONE)
	{
		return '';
	}

	$phoneNumber = isset($input['VALUE']) ? trim($input['VALUE']) : '';
	if (empty($phoneNumber))
	{
		return '';
	}

	if (self::$allowedCountryCodes === null)
	{
		self::$allowedCountryCodes = array_column(GetCountries(), 'CODE');
		self::$allowedCountryCodes[] = CountryProvider::GLOBAL_COUNTRY_CODE;
	}

	$countryCode = isset($input['VALUE_EXTRA']['VALUE_COUNTRY_CODE'])
		? mb_strtoupper(trim($input['VALUE_EXTRA']['VALUE_COUNTRY_CODE']))
		: mb_strtoupper(trim($input['VALUE_COUNTRY_CODE'] ?? ''));
	if (in_array($countryCode, self::$allowedCountryCodes, true))
	{
		return $countryCode; // valid code
	}

	return static::detectCountryByPhone($phoneNumber);
}