You are here

public function LingotekConfigManagementForm::disassociate in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::disassociate()

Disassociate the content from Lingotek.

Parameters

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

File

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

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function disassociate(ConfigMapperInterface $mapper, $langcode, &$context) {
  $context['message'] = $this
    ->t('Disassociating 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
          ->deleteMetadata($entity);
      } catch (LingotekApiException $e) {
        drupal_set_message($this
          ->t('%label deletion failed. Please try again.', [
          '%label' => $entity
            ->label(),
        ]), 'error');
      }
    }
    else {
      try {
        $this->translationService
          ->deleteConfigMetadata($mapper
          ->getPluginId());
      } catch (LingotekApiException $e) {
        drupal_set_message($this
          ->t('%label deletion failed. Please try again.', [
          '%label' => $mapper
            ->getTitle(),
        ]), 'error');
      }
    }
  }
  elseif ($profile = $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId(), FALSE) or TRUE) {
    try {
      $this->translationService
        ->deleteConfigMetadata($mapper
        ->getPluginId());
    } catch (LingotekApiException $e) {
      drupal_set_message($this
        ->t('%label deletion 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');
  }
}