Same name and namespace in other branches
  1. 8.9.x core/modules/content_translation/content_translation.module \content_translation_entity_bundle_info_alter()
  2. 9 core/modules/content_translation/content_translation.module \content_translation_entity_bundle_info_alter()

Implements hook_entity_bundle_info_alter().

File

core/modules/content_translation/content_translation.module, line 247
Allows entities to be translated into different languages.

Code

function content_translation_entity_bundle_info_alter(&$bundles) {

  /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
  $content_translation_manager = \Drupal::service('content_translation.manager');
  foreach ($bundles as $entity_type_id => &$info) {
    foreach ($info as $bundle => &$bundle_info) {
      $bundle_info['translatable'] = $content_translation_manager
        ->isEnabled($entity_type_id, $bundle);
      if ($bundle_info['translatable'] && $content_translation_manager instanceof BundleTranslationSettingsInterface) {
        $settings = $content_translation_manager
          ->getBundleTranslationSettings($entity_type_id, $bundle);

        // If pending revision support is enabled for this bundle, we need to
        // hide untranslatable field widgets, otherwise changes in pending
        // revisions might be overridden by changes in later default revisions.
        $bundle_info['untranslatable_fields.default_translation_affected'] = !empty($settings['untranslatable_fields_hide']) || ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id, $bundle);
      }
    }
  }
}