You are here

protected function ContextUploader::uploadContextBody in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8 src/Context/ContextUploader.php \Drupal\tmgmt_smartling\Context\ContextUploader::uploadContextBody()
  2. 8.2 src/Context/ContextUploader.php \Drupal\tmgmt_smartling\Context\ContextUploader::uploadContextBody()
  3. 8.3 src/Context/ContextUploader.php \Drupal\tmgmt_smartling\Context\ContextUploader::uploadContextBody()

Parameters

$url:

$file:

$proj_settings:

null $content_filename:

Return value

array

1 call to ContextUploader::uploadContextBody()
ContextUploader::upload in src/Context/ContextUploader.php

File

src/Context/ContextUploader.php, line 190

Class

ContextUploader

Namespace

Drupal\tmgmt_smartling\Context

Code

protected function uploadContextBody($url, $file, $proj_settings, $content_filename = NULL) {
  try {
    $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')
      ->getViaUri($file
      ->getFileUri());
    $api = $this
      ->getApiWrapper($proj_settings)
      ->getApi('context');
    $match_params = new MatchContextParameters();
    $match_params
      ->setContentFileUri($content_filename);
    $match_params
      ->setOverrideContextOlderThanDays(0);
    $upload_params = new UploadContextParameters();
    $upload_params
      ->setContent($stream_wrapper_manager
      ->realpath());
    $upload_params
      ->setName($url);
    $upload_params_with_matching = new UploadContextParameters();
    $upload_params_with_matching
      ->setContent($stream_wrapper_manager
      ->realpath());
    $upload_params_with_matching
      ->setName($url);
    $upload_params_with_matching
      ->setMatchParams($match_params);
    $api
      ->uploadAndMatchContextSync($upload_params_with_matching);
    $response = $api
      ->uploadAndMatchContext($upload_params);
  } catch (Exception $e) {
    $response = [];
    watchdog_exception('tmgmt_smartling', $e);
  }
  return $response;
}