You are here

public function ContextUploader::upload in TMGMT Translator Smartling 8

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

Parameters

string $url:

string $filename:

array $proj_settings:

Return value

bool

Throws

EmptyContextParameterException

File

src/Context/ContextUploader.php, line 82

Class

ContextUploader

Namespace

Drupal\tmgmt_smartling\Context

Code

public function upload($url, $filename = '', $proj_settings = []) {
  if (empty($url)) {
    throw new EmptyContextParameterException('Context url must be a non-empty field.');
  }
  try {
    $html = $this
      ->getContextualizedPage($url, $proj_settings);
    $response = $this
      ->uploadContextBody($url, $html, $filename, $proj_settings);
    if (!empty($response['items'])) {
      foreach ($response['items'] as $resource) {
        $this
          ->uploadAsset($resource['url'], $resource['resourceId'], $proj_settings);
      }
    }
  } catch (SmartlingApiException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    return [];
  } catch (SmartlingBaseException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    return [];
  }
  $this->logger
    ->info('Context upload for file @filename completed successfully.', [
    '@filename' => $filename,
  ]);
  return $response;
}