You are here

public function LingotekApi::addContentDocumentWithTargets in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.2 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocumentWithTargets()
  2. 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocumentWithTargets()

Adds a Document and one or more Translation Targets to the Lingotek platform. (used by comments and config chunks currently)

Parameters

LingotekTranslatableEntity $entity: A Drupal entity.

File

lib/Drupal/lingotek/LingotekApi.php, line 165
Defines Drupal\lingotek\LingotekApi

Class

LingotekApi
@file Defines Drupal\lingotek\LingotekApi

Code

public function addContentDocumentWithTargets(LingotekTranslatableEntity $entity) {
  global $_lingotek_locale;
  $success = FALSE;
  $parameters = $this
    ->getCreateWithTargetsParams($entity);
  if ($result = $this
    ->request('addContentDocumentWithTargetsAsync', $parameters)) {
    $entity
      ->setMetadataValue('document_id', $result->id);

    // Comments and Config Chunks are associated with the "default" Lingotek project.
    // Nodes can have their projects selected on a per-node basis, and will need
    // separate consideration if addContentDocumentWithTargets is used for them
    // in the future.
    if (in_array(get_class($entity), array(
      'LingotekComment',
      'LingotekConfigChunk',
    ))) {
      $entity
        ->setMetadataValue('project_id', variable_get('lingotek_project'));
    }
    $success = TRUE;
  }
  return $success;
}