• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/task/files.php
  • Класс: BitrixTasksRestControllersTaskFiles
  • Вызов: Files::attachAction
public function attachAction(CTaskItem $task, int $fileId, array $params = [])
{
	if (!$task->checkAccess(ActionDictionary::ACTION_TASK_EDIT))
	{
		$this->errorCollection->add([new Error('Access denied')]);
		return null;
	}

	$attachmentId = IntegrationDiskRestAttachment::attach(
		$task->getId(),
		$fileId,
		[
			'USER_ID' => CurrentUser::get()->getId(),
			'ENTITY_ID' => IntegrationRestTaskUserField::getTargetEntityId(),
			'FIELD_NAME' => 'UF_TASK_WEBDAV_FILES',
		]
	);
	if (!$attachmentId)
	{
		global $APPLICATION;

		$exception = $APPLICATION->GetException();
		foreach ($exception->GetMessages() as $message)
		{
			$this->errorCollection->add([new Error($message['text'])]);
		}

		return null;
	}

	return ['attachmentId' => $attachmentId];
}