protected function LingotekSettingsTabUtilitiesForm::disassociateAllContentTranslations in Lingotek Translation 8
Disassociate all content translations.
1 call to LingotekSettingsTabUtilitiesForm::disassociateAllContentTranslations()
- LingotekSettingsTabUtilitiesForm::disassociateAllTranslations in src/
Form/ LingotekSettingsTabUtilitiesForm.php - Disassociate all content and config translations.
File
- src/
Form/ LingotekSettingsTabUtilitiesForm.php, line 211 - Contains \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm.
Class
- LingotekSettingsTabUtilitiesForm
- Tab for running Lingotek utilities in the settings page.
Namespace
Drupal\lingotek\FormCode
protected function disassociateAllContentTranslations() {
$error = FALSE;
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$doc_ids = $translation_service
->getAllLocalDocumentIds();
foreach ($doc_ids as $doc_id) {
$entity = $translation_service
->loadByDocumentId($doc_id);
if ($entity === NULL) {
// This entity is somehow orphaned. We can remove the metadata safely.
\Drupal::database()
->delete('lingotek_content_metadata')
->condition('document_id', $doc_id)
->execute();
drupal_set_message(t('There is no entity in Drupal corresponding to the Lingotek document @doc_id. The record for this document has been removed from Drupal.', [
'@doc_id' => $doc_id,
]), 'warning');
}
else {
try {
$translation_service
->deleteMetadata($entity);
} catch (LingotekApiException $exception) {
$error = TRUE;
drupal_set_message(t('The deletion of @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
}
}
if ($error) {
drupal_set_message($this
->t('Some translations may have been disassociated, but some failed.'), 'warning');
}
else {
drupal_set_message($this
->t('All translations have been disassociated.'));
}
return $error;
}