You are here

public function LingotekEntityController::update in Lingotek Translation 3.3.x

Same name and namespace in other branches
  1. 8 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  2. 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  3. 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  4. 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  5. 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  6. 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  7. 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  8. 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  9. 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  10. 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
  11. 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
1 string reference to 'LingotekEntityController::update'
lingotek.routing.yml in ./lingotek.routing.yml
lingotek.routing.yml

File

src/Controller/LingotekEntityController.php, line 250

Class

LingotekEntityController

Namespace

Drupal\lingotek\Controller

Code

public function update($doc_id) {

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $entity = $translation_service
    ->loadByDocumentId($doc_id);
  if (!$entity) {

    // TODO: log warning
    return $this
      ->translationsPageRedirect($entity);
  }
  $bundleInfos = $this->entityTypeBundleInfo
    ->getBundleInfo($entity
    ->getEntityTypeId());
  if (!$entity
    ->getEntityType()
    ->isTranslatable() || !$bundleInfos[$entity
    ->bundle()]['translatable']) {
    \Drupal::messenger()
      ->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for translation.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
      '@bundle_label' => $entity
        ->getEntityType()
        ->getBundleLabel(),
    ]));
    return $this
      ->translationsPageRedirect($entity);
  }
  if (!$this->lingotekConfiguration
    ->isEnabled($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    $this
      ->messenger()
      ->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for Lingotek translation.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
      '@bundle_label' => $entity
        ->getEntityType()
        ->getBundleLabel(),
    ]));
    return $this
      ->translationsPageRedirect($entity);
  }
  try {
    if ($translation_service
      ->updateDocument($entity)) {
      $this
        ->messenger()
        ->addStatus(t('@entity_type %title has been updated.', [
        '@entity_type' => ucfirst($entity
          ->getEntityTypeId()),
        '%title' => $entity
          ->label(),
      ]));
    }
    else {
      $this
        ->messenger()
        ->addError(t('The upload for @entity_type %title failed. Check your configuration and profile and try again.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      ]));
    }
  } catch (LingotekDocumentArchivedException $exception) {
    $this
      ->messenger()
      ->addError(t('Document @entity_type %title has been archived. Please upload again.', [
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '%title' => $entity
        ->label(),
    ]));
  } catch (LingotekDocumentLockedException $exception) {
    $this
      ->messenger()
      ->addError(t('Document @entity_type %title has a new version. The document id has been updated for all future interactions. Please try again.', [
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '%title' => $entity
        ->label(),
    ]));
  } catch (LingotekPaymentRequiredException $exception) {
    $this
      ->messenger()
      ->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
  } catch (LingotekApiException $exception) {
    $this
      ->messenger()
      ->addError(t('The update for @entity_type %title failed. Please try again.', [
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '%title' => $entity
        ->label(),
    ]));
  }
  return $this
    ->translationsPageRedirect($entity);
}