public function LingotekApi::addContentDocument in Lingotek Translation 7.2
Same name and namespace in other branches
- 7.7 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.4 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.5 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.6 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
Add a document to the Lingotek platform.
Uploads the node's field content in the node's selected language.
Parameters
object $node: A Drupal node object.
File
- lib/
Drupal/ lingotek/ LingotekApi.php, line 68 - Defines Drupal\lingotek\LingotekApi
Class
- LingotekApi
- @file Defines Drupal\lingotek\LingotekApi
Code
public function addContentDocument($node, $with_targets = FALSE) {
global $_lingotek_locale;
$success = FALSE;
$project_id = empty($node->lingotek_project_id) ? NULL : $node->lingotek_project_id;
$project_id = empty($project_id) ? lingotek_lingonode($node->nid, 'project_id') : $project_id;
$project_id = empty($project_id) ? variable_get('lingotek_project', NULL) : $project_id;
$vault_id = empty($node->lingotek_vault_id) ? NULL : $node->lingotek_vault_id;
$vault_id = empty($vault_id) ? lingotek_lingonode($node->nid, 'vault_id') : $vault_id;
$vault_id = empty($vault_id) ? variable_get('lingotek_vault', 1) : $vault_id;
$workflow_id = empty($node->workflow_id) ? NULL : $node->workflow_id;
$workflow_id = empty($workflow_id) ? lingotek_lingonode($node->nid, 'workflow_id') : $workflow_id;
$workflow_id = empty($workflow_id) ? variable_get('workflow_id', NULL) : $workflow_id;
$source_language = isset($_lingotek_locale[$node->language]) ? $_lingotek_locale[$node->language] : $_lingotek_locale[lingotek_get_source_language()];
if ($project_id) {
$parameters = array(
'projectId' => $project_id,
'documentName' => $node->title,
'documentDesc' => $node->title,
'format' => $this
->xmlFormat(),
'sourceLanguage' => $source_language,
'tmVaultId' => $vault_id,
'content' => lingotek_xml_node_body($node),
'note' => url('node/' . $node->nid, array(
'absolute' => TRUE,
'alias' => TRUE,
)),
);
if (!empty($workflow_id)) {
$parameters['workflowId'] = $workflow_id;
}
$this
->addAdvancedParameters($parameters, $node);
if ($with_targets) {
$parameters['targetAsJSON'] = LingotekAccount::instance()
->getManagedTargetsAsJSON();
$parameters['applyWorkflow'] = 'true';
// API expects a 'true' string
$result = $this
->request('addContentDocumentWithTargets', $parameters);
}
else {
$result = $this
->request('addContentDocument', $parameters);
}
if ($result) {
lingotek_lingonode($node->nid, 'document_id', $result->id);
lingotek_set_node_and_targets_sync_status($node->nid, LINGOTEK_NODE_SYNC_STATUS_CURRENT, LINGOTEK_TARGET_SYNC_STATUS_PENDING);
$success = TRUE;
}
}
return $success;
}