- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/block.php
- Класс: BitrixLandingBlock
- Вызов: Block::setAttributes
public function setAttributes($data)
{
if ($this->access < $this::ACCESS_W)
{
$this->error->addError(
'ACCESS_DENIED',
Loc::getMessage('LANDING_BLOCK_ACCESS_DENIED')
);
return;
}
$doc = $this->getDom();
$manifest = $this->getManifest();
$wrapper = '#' . $this->getAnchor($this->id);
// collect allowed attrs
$allowedAttrs = [];
self::collectAllowedAttrs($manifest['style']['nodes'], $allowedAttrs);
self::collectAllowedAttrs($manifest['attrs'], $allowedAttrs);
self::collectAllowedAttrs($manifest['cards'], $allowedAttrs);
self::collectAllowedAttrs($manifest['style']['block'], $allowedAttrs);
// update attrs
if ($allowedAttrs)
{
// all allowed attrs from manifest with main selector ([selector] => [data-test, data-test2])
foreach ($allowedAttrs as $selector => $allowed)
{
// it's not interesting for us, if there is no new data for this selector
if ((isset($data[$selector]) && is_array($data[$selector])) || isset($data[$wrapper]) )
{
// set attrs to the block
if ($selector === '#wrapper')
{
$selector = $wrapper;
}
if ($selector == $wrapper)
{
$nodesArray = $doc->getChildNodesArray();
$resultList = [array_pop($nodesArray)];
}
// or by selector
else
{
$resultList = $doc->querySelectorAll($selector);
}
// external data for changing in allowed attrs
foreach ($data[$selector] as $attrKey => $attrData)
{
// if key without position (compatibility)
if (!($attrKey == (string)(int)$attrKey))
{
$attrData = [$attrKey => $attrData];
$attrKey = -1;
}
if (!is_array($attrData))
{
continue;
}
// attrs new data in each selector ([data-test] => value)
foreach ($attrData as $key => $value)
{
if (!in_array($key, $allowed))
{
continue;
}
$key = htmlspecialcharsbx($key);
$value = is_array($value) ? json_encode($value) : $value;
// result nodes by main selector
foreach ($resultList as $pos => $resultNode)
{
// if position of node that we try to find
if ($attrKey == -1 || $attrKey == $pos)
{
$valueBefore = $resultNode->getAttribute($key);
// update node
$resultNode->setAttribute($key, $value);
if (History::isActive())
{
$history = new History($this->getLandingId(), History::ENTITY_TYPE_LANDING);
$history->push('EDIT_ATTRIBUTES', [
'block' => $this,
'selector' => $selector,
'isWrapper' => ($selector === $wrapper),
'attribute' => $key,
'position' => (int)$attrKey,
'valueBefore' => $valueBefore,
'valueAfter' => $value,
]);
}
}
}
}
}
}
}
}
// save result
$this->saveContent($doc->saveHTML());
}