- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/controller/form.php
- Класс: Bitrix\Crm\Controller\Form
- Вызов: Form::getOpenlinesForEmbedAction
public function getOpenlinesForEmbedAction(int $formId, int $count = self::EMBED_DEFAULT_OPENLINES_DISPLAY_COUNT)
{
if (!$this->getFormAccess())
{
$this->addError(new Main\Error('Access denied.', self::ERROR_CODE_FORM_READ_ACCESS_DENIED));
return ['error' => ['status' => 'access denied', 'code' => self::ERROR_CODE_FORM_READ_ACCESS_DENIED]];
}
if ($this->shouldVerifyPhone() && !$this->isPhoneVerified($formId))
{
$this->addError(new Main\Error('Phone doesn\'t verified', self::ERROR_CODE_PHONE_NOT_VERIFIED, ['id' => $formId]));
return [];
}
if (!\Bitrix\Main\Loader::includeModule('imopenlines'))
{
$this->addError(new Main\Error('Module openlines not installed.', self::ERROR_CODE_OPENLINES_READ_ACCESS_DENIED));
return ['error' => ['status' => 'access denied', 'code' => self::ERROR_CODE_OPENLINES_READ_ACCESS_DENIED]];
}
$config = new \Bitrix\Imopenlines\Config();
$requestOptions = self::EMBED_OPENLINES_SHOW_ALL
? []
: ['CHECK_PERMISSION' => \Bitrix\ImOpenlines\Security\Permissions::ACTION_MODIFY]
;
$openlines = $config->getList(
[
'select' => ['ID', 'LINE_NAME', 'USE_WELCOME_FORM', 'WELCOME_FORM_ID', 'WELCOME_FORM_DELAY'],
'filter' => ['=ACTIVE' => 'Y', '=TEMPORARY' => 'N'],
'limit' => $count + 1, // +1 to check for additional lines
],
$requestOptions
);
$form = new WebForm\Form($formId);
$formData = $form->get();
$showMoreLink = false;
if (count($openlines) > $count)
{
$showMoreLink = true;
array_pop($openlines); // +1 to check for additional lines
}
$openlines = $this->prepareOpenlinesDataForEmbed($formId, $openlines);
$buttonForPreview = $previewLink = null;
foreach ($openlines as $line)
{
$buttons = Crm\SiteButton\Manager::getWidgetsByOpenlineId($line['id']);
/** @var Crm\SiteButton\Button $button */
foreach ($buttons as $button)
{
$data = $button->getData();
if ($data['ACTIVE'] === 'Y')
{
$buttonForPreview = $button->getId();
break 2;
}
}
}
if ($buttonForPreview)
{
$previewLink = strtr(WebForm\Script::getPublicFormPath(), [
'#id#' => $formData['ID'],
'#form_id#' => $formData['ID'],
'#form_code#' => $formData['CODE'],
'#form_sec#' => $formData['SECURITY_CODE'],
]);
$previewLink = WebForm\Script::getDomain() . $previewLink . '?view=preview&preview=ol&preview_id='.$buttonForPreview;
}
return [
'formName' => $form->getName(),
'lines' => $openlines,
'url' => [
'allLines' => $this->getOpenlinesUrl(),
],
'showMoreLink' => $showMoreLink,
'previewLink' => $previewLink,
'helpCenterUrl' => self::getHelpCenterUrl(self::EMBED_HELP_CENTER_ID),
'helpCenterId' => self::EMBED_HELP_CENTER_ID,
];
}