You are here

public function LingotekManagementFormBase::cancelTarget in Lingotek Translation 4.0.x

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

Cancel the content from Lingotek.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

File

src/Form/LingotekManagementFormBase.php, line 1508

Class

LingotekManagementFormBase
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function cancelTarget(ContentEntityInterface $entity, $langcode, $job_id, &$context) {
  $context['message'] = $this
    ->t('Cancelling translation for @type %label to language @language.', [
    '@type' => $entity
      ->getEntityType()
      ->getLabel(),
    '%label' => $entity
      ->label(),
    '@language' => $langcode,
  ]);
  $locale = $this->languageLocaleMapper
    ->getLocaleForLangcode($langcode);
  $bundleInfos = $this->entityTypeBundleInfo
    ->getBundleInfo($entity
    ->getEntityTypeId());
  if (!$entity
    ->getEntityType()
    ->isTranslatable() || !$bundleInfos[$entity
    ->bundle()]['translatable']) {
    $this
      ->messenger()
      ->addWarning(t('Cannot cancel @type %label translation to @language. That @bundle_label is not enabled for translation.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
      '@bundle_label' => $entity
        ->getEntityType()
        ->getBundleLabel(),
      '@language' => $langcode,
    ]));
    return;
  }
  if (!$this->lingotekConfiguration
    ->isEnabled($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    $this
      ->messenger()
      ->addWarning(t('Cannot cancel @type %label translation to @language. That @bundle_label is not enabled for Lingotek translation.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
      '@bundle_label' => $entity
        ->getEntityType()
        ->getBundleLabel(),
      '@language' => $langcode,
    ]));
    return;
  }
  if ($profile = $this->lingotekConfiguration
    ->getEntityProfile($entity, FALSE)) {
    try {
      $this->translationService
        ->cancelDocumentTarget($entity, $locale);
    } catch (LingotekDocumentTargetAlreadyCompletedException $e) {
      $this->translationService
        ->checkTargetStatus($entity, $langcode);
      $this
        ->messenger()
        ->addError($this
        ->t('Target %language for @entity_type %title was already completed in the TMS and cannot be cancelled unless the entire document is cancelled.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
        '%language' => $langcode,
      ]));
    } catch (LingotekDocumentNotFoundException $exc) {
      $this
        ->messenger()
        ->addWarning(t('Document @entity_type %title was not found, so nothing to cancel.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      ]));
    } catch (LingotekApiException $exception) {
      $this
        ->messenger()
        ->addError(t('The cancellation of @entity_type %title translation to @language failed. Please try again.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
        '@language' => $langcode,
      ]));
    }
  }
  else {
    $bundleInfos = $this->entityTypeBundleInfo
      ->getBundleInfo($entity
      ->getEntityTypeId());
    $this
      ->messenger()
      ->addWarning($this
      ->t('The @type %label has no profile assigned so it was not processed.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
    ]));
  }
}