• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/replicator/template/service/checklistservice.php
  • Класс: BitrixTasksReplicatorTemplateServiceCheckListService
  • Вызов: CheckListService::copyToTask
public function copyToTask(): Result
{
	$result = new Result();
	try
	{
		$checkListItems = TemplateCheckListFacade::getByEntityId($this->repository->getTemplate()->getId());
		$checkListItems = array_map(
			static function($item) {
				$item['COPIED_ID'] = $item['ID'];
				unset($item['ID']);
				return $item;
			},
			$checkListItems
		);

		$checkListRoots = TaskCheckListFacade::getObjectStructuredRoots($checkListItems, $this->task->getId(), $this->userId);
		foreach ($checkListRoots as $root)
		{
			/** @var CheckList $root */
			$checkListSaveResult = $root->save();
			if (!$checkListSaveResult->isSuccess())
			{
				foreach ($checkListSaveResult->getErrors() as $error)
				{
					$result->addError(new Error($error->getMessage()));
				}
				return $result;
			}
		}
	}
	catch (SystemException $exception)
	{
		$result->addError(new Error($exception->getMessage()));
		return $result;
	}

	return $result;
}