You are here

public function LingotekConfigManagementForm::uploadDocument in Lingotek Translation 8

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

Upload source for translation.

Parameters

\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.

File

src/Form/LingotekConfigManagementForm.php, line 607
Contains \Drupal\Lingotek\Form\LingotekConfigManagementForm.

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function uploadDocument(ConfigMapperInterface $mapper, $language, &$context) {
  $context['message'] = $this
    ->t('Uploading %label.', [
    '%label' => $mapper
      ->getTitle(),
  ]);

  /** @var ConfigEntityInterface $entity */
  $entity = $mapper instanceof ConfigEntityMapper ? $mapper
    ->getEntity() : NULL;
  $profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
    ->getConfigEntityProfile($entity, FALSE) : $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId(), FALSE);
  $document_id = $mapper instanceof ConfigEntityMapper ? $this->translationService
    ->getDocumentId($entity) : $this->translationService
    ->getConfigDocumentId($mapper);

  // If there is no entity, it's a config object and we don't abort based on
  // the profile.
  if ($entity === NULL || $profile !== NULL) {
    if ($mapper instanceof ConfigEntityMapper) {
      try {
        $this->translationService
          ->uploadDocument($entity);
      } catch (LingotekApiException $e) {
        $this->translationService
          ->setSourceStatus($entity, Lingotek::STATUS_ERROR);
        if ($document_id) {
          drupal_set_message($this
            ->t('%label update failed. Please try again.', [
            '%label' => $entity
              ->label(),
          ]), 'error');
        }
        else {
          drupal_set_message($this
            ->t('%label upload failed. Please try again.', [
            '%label' => $entity
              ->label(),
          ]), 'error');
        }
      }
    }
    else {
      try {
        $this->translationService
          ->uploadConfig($mapper
          ->getPluginId());
      } catch (LingotekApiException $e) {
        $this->translationService
          ->setConfigSourceStatus($mapper, Lingotek::STATUS_ERROR);
        if ($document_id) {
          drupal_set_message($this
            ->t('%label update failed. Please try again.', [
            '%label' => $mapper
              ->getTitle(),
          ]), 'error');
        }
        else {
          drupal_set_message($this
            ->t('%label upload failed. Please try again.', [
            '%label' => $mapper
              ->getTitle(),
          ]), 'error');
        }
      }
    }
  }
  else {
    drupal_set_message($this
      ->t('%label has no profile assigned so it was not processed.', [
      '%label' => $mapper
        ->getTitle(),
    ]), 'warning');
  }
}