• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/lib/block/content/engine.php
  • Класс: BitrixFilemanBlockContentEngine
  • Вызов: Engine::addBlocksToDocument
protected function addBlocksToDocument($blocks)
{
	$placeList = $this->document->querySelectorAll('[' . static::BLOCK_PLACE_ATTR . ']');
	if(empty($placeList))
	{
		return;
	}

	// find available places
	$firstPlaceCode = null;
	$bodyPlaceCode = null;
	$placeListByCode = array();
	foreach($placeList as $place)
	{
		/* @var $place BitrixMainWebDOMElement */
		if (!$place || !$place->getAttributeNode(static::BLOCK_PLACE_ATTR))
		{
			continue;
		}

		/*
		// remove child nodes
		foreach($place->getChildNodesArray() as $child)
		{
			$place->removeChild($child);
		}
		*/

		$placeCode = $place->getAttribute(static::BLOCK_PLACE_ATTR);
		$placeListByCode[$placeCode] = $place;
		if(!$firstPlaceCode)
		{
			$firstPlaceCode = $placeCode;
		}

		if(!$bodyPlaceCode && $placeCode == static::BLOCK_PLACE_ATTR_DEF_VALUE)
		{
			$bodyPlaceCode = $placeCode;
		}
	}

	// group block list by existed places
	$blocksByExistType = array();
	foreach($blocks as $placeCode => $blockHtml)
	{
		// if there is no place, find body-place or first place or skip filling place
		if(!array_key_exists($placeCode, $placeListByCode))
		{
			if($bodyPlaceCode)
			{
				$placeCode = $bodyPlaceCode;
			}
			elseif($firstPlaceCode)
			{
				$placeCode = $firstPlaceCode;
			}
			else
			{
				continue;
			}
		}

		$blocksByExistType[$placeCode][] = $blockHtml;
	}

	//fill existed places by blocks
	foreach($blocksByExistType as $placeCode => $blockHtmlList)
	{
		if(!array_key_exists($placeCode, $placeListByCode))
		{
			continue;
		}

		$place = $placeListByCode[$placeCode];
		$place->setInnerHTML(implode("n", $blockHtmlList));
	}
}