You are here

function social_content_translation_install_language_settings_for_entities in Open Social 10.3.x

Install translation configuration.

"Content Translation" module provide UI where we can enabled/disable translations for entity types we want. So here we enabling translations for modules if it have "language.content_settings*" configuration in "config/optional" folder.

1 call to social_content_translation_install_language_settings_for_entities()
social_content_translation_install in modules/custom/social_language/modules/social_content_translation/social_content_translation.install
Implements hook_install().

File

modules/custom/social_language/modules/social_content_translation/social_content_translation.install, line 100
Installation tasks for the Social Language Content Translation module.

Code

function social_content_translation_install_language_settings_for_entities() {
  $config_storage = \Drupal::service('config.storage');

  // Get enabled modules.
  $modules = \Drupal::moduleHandler()
    ->getModuleList();
  foreach ($modules as $module_name => $extension) {

    // Check if modules have target configuration.
    $config_path = drupal_get_path('module', $module_name) . '/config/optional';
    $source = new FileStorage($config_path);
    if (!($list = $source
      ->listAll('language.content_settings'))) {

      // Do nothing.
      continue;
    }
    foreach ($list as $config_name) {

      // Probably, configuration can be already existed if module provided
      // it was enabled after "Content Translation" module was enabled.
      // Otherwise lets install it.
      if (!$config_storage
        ->exists($config_name)) {
        $file = $source
          ->read($config_name);

        // We create a config as an entity because it allows to update field
        // definitions for translated fields.
        // @see content_translation_language_content_settings_insert()
        $config = ContentLanguageSettings::create($file);
        $config
          ->save();
      }
    }
  }
  \Drupal::service('entity_type.bundle.info')
    ->clearCachedBundles();
  \Drupal::service('router.builder')
    ->setRebuildNeeded();
}