- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/webform/requisite.php
- Класс: Bitrix\Crm\WebForm\Requisite
- Вызов: Requisite::getAddressTypes
private function getAddressTypes(int $countryId): array
{
$zoneId = EntityRequisite::getAddressZoneByCountry($countryId);
//ENTITY_TYPE_ID & ENTITY_ID = Requisite relation
//ANCHOR_TYPE_ID & ANCHOR_ID = Contact&Company relation
$types = [];
$fields = EntityAddress::getFieldsInfo();
$shortLabels = EntityAddress::getShortLabels();
foreach ((EntityAddressType::getZoneMap()[$zoneId]['types'] ?? []) as $typeId)
{
$fields = array_filter(
$fields,
function (array $field, $name): bool
{
return !\CCrmFieldInfoAttr::isFieldHasAttribute($field, \CCrmFieldInfoAttr::Immutable)
&& !\CCrmFieldInfoAttr::isFieldHasAttribute($field, \CCrmFieldInfoAttr::ReadOnly)
&& !in_array($name, ['COUNTRY_CODE'])
;
},
ARRAY_FILTER_USE_BOTH
);
$types[] = [
'id' => $typeId,
'type' => 'address',
'name' => EntityRequisite::ADDRESS . '_' . EntityAddressType::resolveName($typeId),
'label' => EntityAddressType::getDescription($typeId),
'fields' => array_map(
function (array $field, $name) use ($typeId, $shortLabels): array
{
$visible = true;
if ($name === 'LOC_ADDR_ID')
{
$visible = false;
}
return [
'type' => $field['TYPE'],
'name' => $name,
'label' => ($shortLabels[$name] ?? '') ?: EntityAddress::getLabel($name, $typeId),
'visible' => $visible,
];
},
$fields,
array_keys($fields)
),
];
}
return $types;
}