You are here

public function Lingotek::uploadDocument in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  2. 4.0.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  3. 3.0.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  4. 3.1.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  5. 3.2.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  6. 3.3.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  7. 3.4.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  8. 3.5.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  9. 3.6.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  10. 3.7.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()
  11. 3.8.x src/Lingotek.php \Drupal\lingotek\Lingotek::uploadDocument()

Uploads a document to the Lingotek service.

Parameters

string $title: The title of the document as it will be seen in the TMS.

$content: The content of the document

string $locale: The Lingotek locale.

string $url: The document url in the site if any. This allows support for in-context review.

\Drupal\lingotek\LingotekProfileInterface $profile: The profile being used.

Return value

mixed

Overrides LingotekInterface::uploadDocument

File

src/Lingotek.php, line 162
Contains \Drupal\lingotek\Lingotek.

Class

Lingotek

Namespace

Drupal\lingotek

Code

public function uploadDocument($title, $content, $locale, $url = NULL, LingotekProfileInterface $profile = NULL) {

  // Handle adding site defaults to the upload here, and leave
  // the handling of the upload call itself to the API.
  $defaults = array(
    'format' => 'JSON',
    'project_id' => $this
      ->get('default.project'),
    'fprm_subfilter_id' => '0e79f34d-f27b-4a0c-880e-cd9181a5d265',
  );
  if ($profile !== NULL && ($project = $profile
    ->getProject())) {
    if ($project !== 'default') {
      $defaults['project_id'] = $project;
    }
  }
  if ($profile !== NULL && ($vault = $profile
    ->getVault())) {
    if ($vault === 'default') {
      $vault = $this
        ->get('default.vault');
    }
    $defaults['vault_id'] = $vault;

    // If we use the project workflow template default vault, we omit the
    // vault parameter and the TMS will decide.
    if ($vault === 'project_workflow_vault') {
      unset($defaults['vault_id']);
    }
  }
  $args = array_merge(array(
    'content' => $content,
    'title' => $title,
    'locale_code' => $locale,
  ), $defaults);
  if ($url !== NULL) {
    $args['external_url'] = $url;
  }
  $response = $this->api
    ->addDocument($args);

  // TODO: Response code should be 202 on success
  return $response;
}