You are here

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

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

Change Translation Profile.

Parameters

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

File

src/Form/LingotekConfigManagementForm.php, line 1299

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function changeProfile(ConfigMapperInterface $mapper, $profile_id = NULL, $job_id = NULL, &$context = NULL) {
  $context['message'] = $this
    ->t('Changing Translation Profile for @type %label.', [
    '@type' => $mapper
      ->getTypeLabel(),
    '%label' => $mapper
      ->getTitle(),
  ]);
  try {

    /** @var \Drupal\Core\Config\ConfigEntityInterface $entity */
    $entity = $mapper instanceof ConfigEntityMapper ? $mapper
      ->getEntity() : NULL;
    if ($mapper instanceof ConfigEntityMapper) {
      $this->lingotekConfiguration
        ->setConfigEntityProfile($entity, $profile_id);
    }
    else {
      $this->lingotekConfiguration
        ->setConfigProfile($mapper
        ->getPluginId(), $profile_id);
    }
  } catch (LingotekApiException $exception) {
    $this
      ->messenger()
      ->addError(t('The Translation Profile change for %title failed. Please try again.', [
      '%title' => $mapper
        ->getTitle(),
    ]));
  }
  if ($profile_id === Lingotek::PROFILE_DISABLED) {

    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $entity = $mapper instanceof ConfigEntityMapper ? $mapper
      ->getEntity() : NULL;
    if ($mapper instanceof ConfigEntityMapper) {
      $this->translationService
        ->setSourceStatus($entity, Lingotek::STATUS_DISABLED);
      $this->translationService
        ->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
    }
    else {
      $this->translationService
        ->setConfigTargetStatuses($mapper, Lingotek::STATUS_DISABLED);
      $this->translationService
        ->setConfigSourceStatus($mapper, Lingotek::STATUS_DISABLED);
    }
  }
  else {
    if ($mapper instanceof ConfigEntityMapper) {
      $entity = $mapper
        ->getEntity();
      if ($this->translationService
        ->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
        if ($this->translationService
          ->getDocumentId($entity) !== NULL) {
          $this->translationService
            ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
        }
        else {
          $this->translationService
            ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
        }
        if ($this->translationService
          ->getDocumentId($entity)) {
          $this->translationService
            ->checkTargetStatuses($entity);
        }
      }
    }
    else {
      if ($this->translationService
        ->getConfigSourceStatus($mapper) == Lingotek::STATUS_DISABLED) {
        if ($this->translationService
          ->getConfigDocumentId($mapper) !== NULL) {
          $this->translationService
            ->setConfigSourceStatus($mapper, Lingotek::STATUS_CURRENT);
        }
        else {
          $this->translationService
            ->setConfigSourceStatus($mapper, Lingotek::STATUS_CURRENT);
        }
        if ($this->translationService
          ->getConfigDocumentId($mapper)) {
          $this->translationService
            ->checkConfigTargetStatuses($mapper
            ->getPluginId());
        }
      }
    }
  }
}