You are here

public function LingotekContentTranslationService::uploadDocument in Lingotek Translation 8

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

Uploads a document to the Lingotek service.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity being uploaded.

Return value

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

Overrides LingotekContentTranslationServiceInterface::uploadDocument

File

src/LingotekContentTranslationService.php, line 615
Contains \Drupal\lingotek\LingotekContentTranslationService.

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function uploadDocument(ContentEntityInterface $entity) {
  if (!empty($entity->lingotek_document_id->value)) {
    return $this
      ->updateDocument($entity);
  }
  $source_data = $this
    ->getSourceData($entity);
  $document_name = $entity
    ->bundle() . ' (' . $entity
    ->getEntityTypeId() . '): ' . $entity
    ->label();
  $url = $entity
    ->hasLinkTemplate('canonical') ? $entity
    ->toUrl()
    ->setAbsolute(TRUE)
    ->toString() : NULL;
  $profile = $this->lingotekConfiguration
    ->getEntityProfile($entity);

  // Allow other modules to alter the data before is uploaded.
  \Drupal::moduleHandler()
    ->invokeAll('lingotek_content_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, $profile);
  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;
}