• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/folder.php
  • Класс: BitrixLandingFolder
  • Вызов: Folder::getBreadCrumbs
static function getBreadCrumbs(int $folderId, ?int $siteId = null): array
{
	static $cacheFolders = [];
	$crumbs = [];

	if (!$siteId)
	{
		$res = self::getList([
			'select' => [
				'SITE_ID'
			],
			'filter' => [
				'ID' => $folderId
			],
			'limit' => 1
		]);
		if ($row = $res->fetch())
		{
			$siteId = $row['SITE_ID'];
		}
	}

	if (!$siteId)
	{
		return $crumbs;
	}

	// get all folder's chunks for the site
	if (!array_key_exists($siteId, $cacheFolders))
	{
		$cacheFolders[$siteId] = [];
		$res = self::getList([
			'select' => [
				'ID', 'TITLE', 'INDEX_ID', 'CODE',
				'PARENT_ID', 'ACTIVE', 'DELETED'
			],
			'filter' => [
				'SITE_ID' => $siteId
			]
		]);
		while ($row = $res->fetch())
		{
			$cacheFolders[$siteId][$row['ID']] = $row;
		}
	}

	if (!$cacheFolders[$siteId])
	{
		return $crumbs;
	}

	// build recursively
	$folders = $cacheFolders[$siteId];
	do
	{
		if (!isset($folders[$folderId]))
		{
			break;
		}
		$crumbs[] = $folders[$folderId];
		$folderId = $folders[$folderId]['PARENT_ID'];
	}
	while ($folderId);

	return array_reverse($crumbs);
}