- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/assets/preprocessing/crmcontacts.php
- Класс: BitrixLandingAssetsPreProcessingCrmContacts
- Вызов: CrmContacts::processing
static function processing(Block $block): void
{
$content = $block->getContent();
if (!$content)
{
return;
}
// get requisites from my companies
$contacts = self::getContacts();
$company = $contacts[self::COMPANY_KEY];
$phones = $contacts[self::PHONES_KEY];
$emails = $contacts[self::EMAILS_KEY];
// todo: just one contact to replace
// if phones or email found, replace markers
$replaced = 0;
$content = preg_replace_callback(
'/#(PHONE|EMAIL)([d]+)#/',
static function ($matches) use ($phones, $emails)
{
$key = $matches[2];
$sources = ($matches[1] === 'PHONE') ? $phones : $emails;
return $sources[$key] ?? $sources[0];
},
$content,
-1,
$replaced
);
if (mb_strpos($content, '#COMPANY#') !== false)
{
$content = str_replace('#COMPANY#', $company, $content);
$replaced++;
}
if ($replaced)
{
$block->saveContent($content);
$block->save();
}
}