- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/publicaction/landing.php
- Класс: Bitrix\Landing\PublicAction\Landing
- Вызов: Landing::addBlock
static function addBlock($lid, array $fields, bool $preventHistory = false)
{
LandingCore::setEditMode();
Hook::setEditMode(true);
$result = new PublicActionResult();
$landing = LandingCore::createInstance($lid);
if ($landing->exist())
{
$data = array(
'PUBLIC' => 'N',
);
if (isset($fields['ACTIVE']))
{
$data['ACTIVE'] = $fields['ACTIVE'];
}
if (isset($fields['CONTENT']))
{
$data['CONTENT'] = Manager::sanitize(
$fields['CONTENT'],
$bad
);
}
// sort
if (isset($fields['AFTER_ID']))
{
$blocks = $landing->getBlocks();
if (isset($blocks[$fields['AFTER_ID']]))
{
$data['SORT'] = $blocks[$fields['AFTER_ID']]->getSort() + 1;
}
}
else
{
$data['SORT'] = -1;
}
$preventHistory ? History::deactivate() : History::activate();
$newBlockId = $landing->addBlock($fields['CODE'] ?? '', $data, true);
$landing->resortBlocks();
// want return content ob block
if (
isset($fields['RETURN_CONTENT']) &&
$fields['RETURN_CONTENT'] == 'Y'
)
{
$return = BlockCore::getBlockContent($newBlockId, true);
}
else
{
$return = $newBlockId;
}
$result->setResult($return);
}
$result->setError($landing->getError());
return $result;
}