You are here

public function LingotekConfigurationService::setContentTranslationSettings in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 4.0.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  2. 3.1.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  3. 3.2.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  4. 3.3.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  5. 3.5.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  6. 3.6.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  7. 3.7.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()
  8. 3.8.x src/LingotekConfigurationService.php \Drupal\lingotek\LingotekConfigurationService::setContentTranslationSettings()

Sets Lingotek translatability settings of multiple content.

Return value

\Drupal\Core\Entity\EntityTypeInterface[] An array of entity types that are enabled for Lingotek content translation.

Overrides LingotekMultipleContentConfigurationServiceInterface::setContentTranslationSettings

File

src/LingotekConfigurationService.php, line 59

Class

LingotekConfigurationService
Service for managing lingotek configuration.

Namespace

Drupal\lingotek

Code

public function setContentTranslationSettings(array $contentData) {
  $config = \Drupal::configFactory()
    ->getEditable('lingotek.settings');
  foreach ($contentData as $entity_type_id => $entityTypeData) {
    foreach ($entityTypeData as $bundle_id => $bundleData) {
      if (isset($bundleData['enabled'])) {
        $key = 'translate.entity.' . $entity_type_id . '.' . $bundle_id . '.enabled';
        $config
          ->set($key, $bundleData['enabled']);
      }
      if (isset($bundleData['fields'])) {
        foreach ($bundleData['fields'] as $field_id => $fieldValue) {
          if (strpos($field_id, ':properties') === FALSE) {
            $key = 'translate.entity.' . $entity_type_id . '.' . $bundle_id . '.field.' . $field_id;
            if ($fieldValue && !$config
              ->get($key)) {
              $config
                ->set($key, $fieldValue);
            }
            elseif (!$fieldValue && $config
              ->get($key)) {
              $config
                ->clear($key);
            }
          }
          else {

            // If it's properties, we set whatever we got.
            $key = 'translate.entity.' . $entity_type_id . '.' . $bundle_id . '.field.' . $field_id;
            $config
              ->set($key, $fieldValue);
          }
        }
      }
      if (isset($bundleData['profile'])) {
        $config
          ->set('translate.entity.' . $entity_type_id . '.' . $bundle_id . '.profile', $bundleData['profile']);
      }
    }
  }
  $config
    ->save();
}