You are here

public function LingotekConfigManagementForm::cancel in Lingotek Translation 3.4.x

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

Cancel the content from Lingotek.

Parameters

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

File

src/Form/LingotekConfigManagementForm.php, line 1198

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function cancel(ConfigMapperInterface $mapper, $langcode, $job_id, &$context) {
  $context['message'] = $this
    ->t('Cancelling all translations for %label.', [
    '%label' => $mapper
      ->getTitle(),
  ]);
  $entity = $mapper instanceof ConfigEntityMapper ? $mapper
    ->getEntity() : NULL;
  $profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
    ->getConfigEntityProfile($entity, FALSE) : $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId(), FALSE);

  // 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
          ->cancelDocument($entity);
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label cancellation failed. Please try again.', [
          '%label' => $entity
            ->label(),
        ]));
      }
    }
    else {
      try {
        $this->translationService
          ->cancelConfigDocument($mapper
          ->getPluginId());
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label cancellation failed. Please try again.', [
          '%label' => $mapper
            ->getTitle(),
        ]));
      }
    }
  }
  elseif ($profile = $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId(), FALSE) or TRUE) {
    try {
      $this->translationService
        ->cancelConfigDocument($mapper
        ->getPluginId());
    } catch (LingotekApiException $e) {
      $this
        ->messenger()
        ->addError($this
        ->t('%label cancellation failed. Please try again.', [
        '%label' => $mapper
          ->getTitle(),
      ]));
    }
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('%label has no profile assigned so it was not processed.', [
      '%label' => $mapper
        ->getTitle(),
    ]));
  }
}