You are here

protected function LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig in Lingotek Translation 3.1.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  2. 4.0.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  3. 3.0.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  4. 3.2.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  5. 3.3.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  6. 3.4.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  7. 3.5.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  8. 3.6.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  9. 3.7.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()
  10. 3.8.x tests/src/Functional/LingotekTestBase.php \Drupal\Tests\lingotek\Functional\LingotekTestBase::saveLingotekContentTranslationSettingsViaConfig()

Save Lingotek content translation settings.

Example:

$this
  ->saveLingotekContentTranslationSettings([
  'node' => [
    'article' => [
      'profiles' => 'automatic',
      'fields' => [
        'title' => 1,
        'body' => 1,
      ],
      'moderation' => [
        'upload_status' => 'draft',
        'download_transition' => 'request_review',
      ],
    ],
  ],
  'paragraph' => [
    'image_text' => [
      'fields' => [
        'field_image_demo' => [
          'title',
          'alt',
        ],
        'field_text_demo' => 1,
      ],
    ],
  ],
]);

Parameters

array $settings: The settings we want to save.

File

tests/src/Functional/LingotekTestBase.php, line 623

Class

LingotekTestBase
Base class for Lingotek test. Performs authorization of the account.

Namespace

Drupal\Tests\lingotek\Functional

Code

protected function saveLingotekContentTranslationSettingsViaConfig($settings) {
  $config = \Drupal::configFactory()
    ->getEditable('lingotek.settings');
  foreach ($settings as $entity_type_id => $entity_type_settings) {
    foreach ($entity_type_settings as $bundle => $bundle_settings) {
      $config
        ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.enabled', TRUE);
      if (isset($bundle_settings['profiles']) && $bundle_settings['profiles'] !== NULL) {
        $config
          ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.profile', $bundle_settings['profiles']);
      }
      foreach ($bundle_settings['fields'] as $field_id => $field_properties) {
        $config
          ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.field.' . $field_id, TRUE);
        if (is_array($field_properties)) {
          foreach ($field_properties as $field_property) {
            $config
              ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.field.' . $field_id . ':properties.' . $field_property, $field_property);
          }
        }
      }
      if (isset($bundle_settings['moderation']) && $bundle_settings['moderation'] !== NULL) {
        $config
          ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.content_moderation.upload_status', $bundle_settings['moderation']['upload_status']);
        $config
          ->set('translate.entity.' . $entity_type_id . '.' . $bundle . '.content_moderation.download_transition', $bundle_settings['moderation']['download_transition']);
      }
    }
  }
  $config
    ->save();
}