- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/publicaction/block.php
- Класс: BitrixLandingPublicActionBlock
- Вызов: Block::updateContent
static function updateContent($lid, $block, $content, $designed = false, bool $preventHistory = false)
{
$result = new PublicActionResult();
$error = new BitrixLandingError;
Landing::setEditMode();
if (Utils::isTrue($designed))
{
if (!RestrictionManager::isAllowed('limit_crm_superblock'))
{
return $result;
}
}
if (strpos($content, 'block-wrapper'))
{
$content = preg_replace('/^]+>(.*?)$/is', '$1', $content);
}
$landing = Landing::createInstance($lid, [
'blocks_id' => $block
]);
// try find the block in landing instance
if ($landing->exist())
{
$block = intval($block);
$blocks = $landing->getBlocks();
if (isset($blocks[$block]))
{
// remove extra files
$newContent = Manager::sanitize($content, $bad);
$filesBeforeSave = File::getFilesFromBlockContent(
$block,
$blocks[$block]->getContent()
);
$filesAfterSave = File::getFilesFromBlockContent(
$block,
$newContent
);
$filesRest = array_intersect($filesBeforeSave, $filesAfterSave);
$filesDelete = [];
foreach ($filesBeforeSave as $fileId)
{
if (!in_array($fileId, $filesRest))
{
$filesDelete[] = $fileId;
}
}
if ($filesDelete)
{
File::deleteFromBlock($block, $filesDelete);
}
if (!$preventHistory)
{
History::activate();
$history = new History($lid, History::ENTITY_TYPE_LANDING);
$history->push('UPDATE_CONTENT', [
'block' => $blocks[$block]->getId(),
'contentBefore' => $blocks[$block]->getContent(),
'contentAfter' => $newContent,
'designed' => $designed,
]);
}
else
{
History::deactivate();
}
// update content
$blocks[$block]->saveContent(
$newContent,
Utils::isTrue($designed)
);
AssetsPreProcessing::blockUpdateNodeProcessing(
$blocks[$block]
);
$result->setResult(
$blocks[$block]->save()
);
$result->setError($blocks[$block]->getError());
}
else
{
$error->addError(
'BLOCK_NOT_FOUND',
Loc::getMessage('LANDING_BLOCK_NOT_FOUND')
);
}
}
$result->setError($landing->getError());
return $result;
}