- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/note/source.php
- Класс: BitrixLandingNoteSource
- Вызов: Source::createFromSource
static function createFromSource(int $kbId, string $sourceType, int $sourceId): ?array
{
if (in_array($sourceType, self::AVAILABLE_SOURCES))
{
$class = __NAMESPACE__ . '\Source\' . $sourceType;
$data = $class::getData($sourceId);
if ($data)
{
Landing::setEditMode();
if (!$kbId)
{
$kbId = self::getLastCreatedSite();
}
$res = Landing::add([
'TITLE' => $data['TITLE'],
'SITE_ID' => $kbId,
'ACTIVE' => 'N',
'PUBLIC' => 'N'
]);
if ($res->isSuccess())
{
Target::rememberLastSite($res->getId());
$landing = Landing::createInstance($res->getId());
Site::addLandingToMenu($landing->getSiteId(), [
'ID' => $landing->getId(),
'TITLE' => $landing->getTitle()
]);
// add block to the landing
foreach ($data['BLOCKS'] as $blockData)
{
$blockMeta = self::getBlockMetaByType($blockData['type']);
if ($blockMeta)
{
$blockId = $landing->addBlock($blockMeta['code'], [
'PUBLIC' => 'N'
]);
if ($blockId)
{
$block = $landing->getBlockById($blockId);
if ($blockData['type'] == 'img')
{
// for correct saving we should set file to the block
File::addToBlock($blockId, $blockData['content']['id']);
}
$block->updateNodes([
$blockMeta['selector'] => [$blockData['content']]
]);
$block->save();
}
}
}
return [
'ID' => $landing->getId(),
'TITLE' => $landing->getTitle(),
'PUBLIC_URL' => $landing->getPublicUrl()
];
}
}
}
return null;
}