You are here

public function LingotekConfigTranslationService::uploadDocument in Lingotek Translation 8

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

Uploads a document to the Lingotek service.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity being uploaded.

Return value

boolean TRUE if the document was uploaded successfully, FALSE if not.

Overrides LingotekConfigTranslationServiceInterface::uploadDocument

File

src/LingotekConfigTranslationService.php, line 359
Contains \Drupal\lingotek\LingotekConfigTranslationService.

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function uploadDocument(ConfigEntityInterface $entity) {
  if (!empty($this
    ->getDocumentId($entity))) {
    return $this
      ->updateDocument($entity);
  }
  $source_data = $this
    ->getSourceData($entity);
  $document_name = $entity
    ->id() . ' (config): ' . $entity
    ->label();
  $url = $entity
    ->hasLinkTemplate('edit-form') ? $entity
    ->toUrl()
    ->setAbsolute()
    ->toString() : NULL;

  // Allow other modules to alter the data before is uploaded.
  \Drupal::moduleHandler()
    ->invokeAll('lingotek_config_entity_document_upload', [
    &$source_data,
    &$entity,
    &$url,
  ]);
  $encoded_data = json_encode($source_data);
  $document_id = $this->lingotek
    ->uploadDocument($document_name, $encoded_data, $this
    ->getSourceLocale($entity), $url, $this->lingotekConfiguration
    ->getConfigEntityProfile($entity));
  if ($document_id) {
    $this
      ->setDocumentId($entity, $document_id);
    $this
      ->setSourceStatus($entity, Lingotek::STATUS_IMPORTING);
    $this
      ->setTargetStatuses($entity, Lingotek::STATUS_REQUEST);
    return $document_id;
  }
  return FALSE;
}