• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/component/itemlist.php
  • Класс: Bitrix\Crm\Component\ItemList
  • Вызов: ItemList::init
protected function init(): void
{
	parent::init();

	if($this->getErrors())
	{
		return;
	}

	$entityTypeId = (int)$this->arParams['entityTypeId'];
	$type = Service\Container::getInstance()->getTypeByEntityTypeId($entityTypeId);
	if (!$type && \CCrmOwnerType::isDynamicTypeBasedStaticEntity($entityTypeId))
	{
		// force creating type
		if ($entityTypeId === \CCrmOwnerType::SmartInvoice)
		{
			Service\Factory\SmartInvoice::createTypeIfNotExists();
		}
		elseif ($entityTypeId === \CCrmOwnerType::SmartDocument)
		{
			Service\Factory\SmartDocument::createTypeIfNotExists();
		}
		$type = Service\Container::getInstance()->getTypeByEntityTypeId($entityTypeId);
	}
	if (!$type)
	{
		$this->errorCollection[] = new Error(Loc::getMessage('CRM_TYPE_TYPE_NOT_FOUND'));
		return;
	}

	$this->entityTypeId = $type->getEntityTypeId();

	$router = Container::getInstance()->getRouter();
	$router->setCurrentListView($this->entityTypeId, $this->getListViewType());

	$this->factory = Service\Container::getInstance()->getFactory($this->entityTypeId);
	$this->kanbanEntity = Kanban\Entity::getInstance($this->factory->getEntityName());

	if($this->factory->isCategoriesSupported())
	{
		$category = $this->initCategory();
		if (!is_null($category))
		{
			$this->category = $category;
			$this->kanbanEntity->setCategoryId($this->category->getId());
		}
	}

	if ($this->category)
	{
		$canReadThisCategory = $this->userPermissions->canReadTypeInCategory(
			$this->entityTypeId,
			$this->category->getId()
		);
	}
	else
	{
		$canReadThisCategory = $this->userPermissions->canReadType($this->entityTypeId);
	}
	if (!$canReadThisCategory)
	{
		if($this->factory->isCategoriesEnabled())
		{
			// if user can not read current category, but can read some another - make the redirect there.
			foreach ($this->factory->getCategories() as $category)
			{
				if ($this->userPermissions->canReadTypeInCategory($this->entityTypeId, $category->getId()))
				{
					LocalRedirect(
						$router->getItemListUrlInCurrentView(
							$this->entityTypeId,
							$category->getId()
						)
					);
					return;
				}
			}
		}
		$this->errorCollection[] = new Error(Loc::getMessage('CRM_COMMON_ERROR_ACCESS_DENIED'));
		return;
	}

	$filterFactory = Container::getInstance()->getFilterFactory();
	$settings = $filterFactory->getSettings(
		$this->factory->getEntityTypeId(),
		$this->getGridId(),
		[
			'categoryId' => $this->getCategoryId(),
			'type' => $type,
		]
	);
	$this->provider = $filterFactory->getDataProvider($settings);
	$this->ufProvider = $filterFactory->getUserFieldDataProvider($settings);
	$this->filter = $filterFactory->createFilter($settings->getID(), $this->provider, [$this->ufProvider]);

	EntityRelationTable::initiateClearingDuplicateSourceElementsWithInterval($this->factory->getEntityTypeId());
}