function lingotek_update_8001 in Lingotek Translation 8.2
Same name and namespace in other branches
- 8 lingotek.install \lingotek_update_8001()
Implements hook_update_N().
File
- ./
lingotek.install, line 122 - Install, update and uninstall functions for the Lingotek module.
Code
function lingotek_update_8001() {
// Get all mappers and update config entity ones, but not field ones.
/** @var \Drupal\config_translation\ConfigMapperManager $mapper_manager */
$mapper_manager = \Drupal::service('plugin.manager.config_translation.mapper');
$mappers = $mapper_manager
->getMappers();
foreach ($mappers as $mapper_id => $mapper) {
if ($mapper instanceof ConfigEntityMapper && !$mapper instanceof ConfigFieldMapper) {
$ids = \Drupal::entityTypeManager()
->getStorage($mapper_id)
->getQuery()
->exists('third_party_settings.lingotek.lingotek_document_id')
->execute();
if (!empty($ids)) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface[] $entities */
$entities = \Drupal::entityTypeManager()
->getStorage($mapper_id)
->loadMultiple($ids);
foreach ($entities as $entity) {
$settings = $entity
->getThirdPartySettings('lingotek');
$metadata = LingotekConfigMetadata::loadByConfigName($entity
->getEntityTypeId() . '.' . $entity
->id());
$metadata
->setDocumentId($settings['lingotek_document_id']);
$metadata
->setSourceStatus($settings['lingotek_translation_source']);
$metadata
->setTargetStatus($settings['lingotek_translation_status']);
$metadata
->setHash($settings['lingotek_hash']);
$metadata
->save();
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_document_id');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_translation_source');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_translation_status');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_hash');
$entity
->save();
}
}
}
}
// Take care of fields now.
$ids = \Drupal::entityTypeManager()
->getStorage('field_config')
->getQuery()
->exists('third_party_settings.lingotek.lingotek_document_id')
->execute();
if (!empty($ids)) {
$entities = \Drupal::entityTypeManager()
->getStorage('field_config')
->loadMultiple($ids);
foreach ($entities as $entity) {
$settings = $entity
->getThirdPartySettings('lingotek');
$metadata = LingotekConfigMetadata::loadByConfigName($entity
->getEntityTypeId() . '.' . $entity
->id());
$metadata
->setDocumentId($settings['lingotek_document_id']);
$metadata
->setSourceStatus($settings['lingotek_translation_source']);
$metadata
->setTargetStatus($settings['lingotek_translation_status']);
$metadata
->setHash($settings['lingotek_hash']);
$metadata
->save();
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_document_id');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_translation_source');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_translation_status');
$entity
->unsetThirdPartySetting('lingotek', 'lingotek_hash');
$entity
->save();
}
}
}