• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/landingsource/element.php
  • Класс: BitrixIblockLandingSourceElement
  • Вызов: Element::onBuildSourceListHandler
static function onBuildSourceListHandler(MainEvent $event)
{
	/** @var LandingSourceSelector $selector */
	$selector = $event->getParameter('SELECTOR');

	$iblockList = [];
	$catalogs = [];
	$restrictions = $selector->getModuleRestrictions('iblock');
	if (!empty($restrictions))
	{
		$getCatalogs = $selector->checkSiteMode([LandingSourceSelector::SITE_MODE_STORE]);
		if (!empty($restrictions['IBLOCK_ID']) && is_array($restrictions['IBLOCK_ID']))
		{
			$catalogs = static::getCatalogs($restrictions['IBLOCK_ID']);
			if (!empty($catalogs))
				$catalogs = array_fill_keys($catalogs, true);

			$filter = ['ID' => $restrictions['IBLOCK_ID']];
			if (!empty($restrictions['SITE_ID']))
			{
				$filter['SITE_ID'] = $restrictions['SITE_ID'];
			}
			$iterator = CIBlock::GetList(['SORT' => 'ASC'], $filter, false);
			while ($row = $iterator->Fetch())
			{
				$row['ID'] = (int)$row['ID'];
				if (!$getCatalogs && isset($catalogs[$row['ID']]))
				{
					continue;
				}
				$iblockList[] = [
					'ID' => $row['ID'],
					'TITLE' => $row['NAME']
				];
			}
			unset($row, $iterator);
			unset($filter);
		}
	}
	unset($restrictions);
	if (empty($iblockList))
	{
		return new MainEventResult(MainEventResult::ERROR, null, 'iblock');
	}

	$elementFields = static::getElementFields();
	$productFields = static::getProductFields();

	$result = [];
	foreach ($iblockList as $iblock)
	{
		$sourceId = self::SELECTOR_ENTITY.$iblock['ID'];
		$path = $selector->getSourceFilterBaseUri('iblock', $sourceId);
		$action = $selector->getResultAction();

		switch ($action['TYPE'])
		{
			case LandingSourceSelector::ACTION_TYPE_EVENT:
				$resultActionType = IblockComponentSelectorEntity::RESULT_ACTION_TYPE_EVENT;
				break;
			case LandingSourceSelector::ACTION_TYPE_SLIDER:
				$resultActionType = IblockComponentSelectorEntity::RESULT_ACTION_TYPE_SLIDER;
				break;
			default:
				$resultActionType = '';
				break;
		}
		if ($resultActionType === '')
			continue;

		$actionList = $selector->getDefaultLinkActions();
		$fields = $elementFields;
		if (isset($catalogs[$iblock['ID']]))
		{
			$fields = array_merge($fields, $productFields);
			$actionList = array_merge($actionList, static::getProductActionList());
		}

		$properties = static::getIblockProperties($iblock['ID']);
		if (!empty($properties))
			$fields = array_merge($fields, $properties);
		unset($properties);

		$fields = array_merge($fields, static::getLinkDefinition($actionList));
		unset($actionList);

		$dataSettings = [
			'ORDER' => static::getOrderFields($fields),
			'FIELDS' => static::getShowedFields($fields)
		];

		$parameters = [
			'GRID_ID' => 'iblock'.$sourceId.'_selector',
			'BASE_LINK' => $path->getUri(),
			'IBLOCK_ID' => $iblock['ID'],
			'MULTIPLE_SELECT' => 'N',
			'USE_MODE' => IblockComponentSelectorEntity::MODE_SLIDER,
			'RESULT_ACTION_TYPE' => $resultActionType,
			'RESULT_ACTION_NAME' => $action['NAME'],
			'RESULT_DATA_TYPE' => IblockComponentSelectorEntity::RESULT_DATA_TYPE_FILTER,
			'RESULT_DATA_SET_LIST' => [],
			'PAGETITLE_FILTER' => 'Y',
			'SIMPLE_PRODUCTS' => 'Y'
		];

		$row = [
			'SOURCE_ID' => $sourceId,
			'TITLE' => $iblock['TITLE'],
			'TYPE' => LandingSourceSelector::SOURCE_TYPE_COMPONENT,
			'SETTINGS' => [
				'COMPONENT_NAME' => 'bitrix:iblock.selector.landing',
				'COMPONENT_TEMPLATE_NAME' => '.default',
				'COMPONENT_PARAMS' => $parameters,
				'WRAPPER' => [
					'USE_PADDING' => false,
					'PLAIN_VIEW' => false,
					'USE_UI_TOOLBAR' => 'N'
				]
			],
			'SOURCE_FILTER' => [
				'IBLOCK_ID' => $iblock['ID'],
				'ACTIVE_DATE' => 'Y',
				'CHECK_PERMISSIONS' => 'Y',
				'MIN_PERMISSION' => 'R'
			],
			'DATA_SETTINGS' => $dataSettings,
			'DATA_LOADER' => 'BitrixIblockLandingSourceDataLoader'
		];
		$result[] = $row;
	}
	unset($sourceId, $path, $action, $dataSettings, $parameters, $row, $iblock);
	unset($iblockList);

	unset($selector);

	return new MainEventResult(MainEventResult::SUCCESS, $result, 'iblock');
}