- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/node/link.php
- Класс: BitrixLandingNodeLink
- Вызов: Link::saveNode
static function saveNode(BitrixLandingBlock $block, $selector, array $data): array
{
$result = [];
$manifest = $block->getManifest();
$globalSkipContent = false;
if ($manifest['nodes'][$selector]['skipContent'] ?? false)
{
$globalSkipContent = true;
}
$doc = $block->getDom();
$resultList = $doc->querySelectorAll($selector);
$valueBefore = static::getNode($block, $selector);
$isIframe = self::isFrame();
foreach ($data as $pos => $value)
{
$text = (isset($value['text']) && is_string($value['text'])) ? trim($value['text']) : '';
$href = (isset($value['href']) && is_string($value['href'])) ? trim($value['href']) : '';
$query = (isset($value['query']) && is_string($value['query'])) ? trim($value['query']) : '';
$target = (isset($value['target']) && is_string($value['target'])) ? trim(mb_strtolower($value['target'])) : '';
$attrs = isset($value['attrs']) ? (array)$value['attrs'] : array();
$skipContent = $globalSkipContent || (isset($value['skipContent']) ? (boolean)$value['skipContent'] : false);
$result[$pos]['attrs'] = [];
if ($query)
{
$href .= (mb_strpos($href, '?') === false && !$isIframe) ? '?' : '&';
$href .= $query;
}
if (isset($value['text']) && !$text)
{
$text = ' ';
}
if (isset($resultList[$pos]))
{
if (
$text &&
!$skipContent &&
trim($resultList[$pos]->getTextContent()) != ''
)
{
$text = htmlspecialcharsbx($text);
$result[$pos]['content'] = $text;
$resultList[$pos]->setInnerHTML($text);
}
if ($href != '')
{
$result[$pos]['attrs']['href'] = $href;
$resultList[$pos]->setAttribute('href', $href);
}
if (self::isAllowedTarget($target))
{
$result[$pos]['attrs']['target'] = $target;
$resultList[$pos]->setAttribute('target', $target);
}
$allowedAttrs = self::allowedAttrs();
if (!empty($attrs))
{
foreach ($attrs as $code => $val)
{
if ($val && in_array($code, $allowedAttrs))
{
$result[$pos]['attrs'][$code] = $val;
$resultList[$pos]->setAttribute($code, $val);
}
}
}
else
{
foreach ($allowedAttrs as $attr)
{
$resultList[$pos]->removeAttribute($attr);
}
}
if (History::isActive())
{
$history = new History($block->getLandingId(), History::ENTITY_TYPE_LANDING);
$history->push('EDIT_LINK', [
'block' => $block,
'selector' => $selector,
'position' => (int)$pos,
'valueBefore' => $valueBefore[$pos],
'valueAfter' => $value,
]);
}
}
}
return $result;
}