• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/controller/category.php
  • Класс: Bitrix\Crm\Controller\Category
  • Вызов: Category::deleteAction
public function deleteAction(int $entityTypeId, int $id): void
{
	$factory = $this->getFactory($entityTypeId);
	if (!$factory)
	{
		return;
	}
	$category = $factory->getCategory($id);
	if (!$category)
	{
		$this->addError(ErrorCode::getNotFoundError());
		return;
	}

	if ($category->getIsSystem())
	{
		$this->addError(
			new Error(
				Loc::getMessage('CRM_TYPE_CATEGORY_DELETE_ERROR_SYSTEM'),
				ErrorCode::REMOVING_DISABLED
			)
		);

		return;
	}

	if (!$this->userPermissions->canDeleteCategory($category))
	{
		$this->addError(ErrorCode::getAccessDeniedError());
		return;
	}

	if (!$this->userPermissions->canDeleteCategory($category))
	{
		$this->addError(ErrorCode::getAccessDeniedError());
		return;
	}

	$result = $category->delete();
	if (!$result->isSuccess())
	{
		$this->addErrors($result->getErrors());
	}
}