+ // Determine if the fields are translatable.
+ $bundles_names = $field_storage->getBundles();
+ $translation_join_type = FALSE;
+ $fields = [];
+ $translatable_configs = [];
+ $untranslatable_configs = [];
+ $untranslatable_config_bundles = [];
+
+ foreach ($bundles_names as $bundle) {
+ $fields[$bundle] = FieldConfig::loadByName($entity_type->id(), $bundle, $field_name);
+ }
+ foreach ($fields as $bundle => $config_entity) {
+ if (!empty($config_entity)) {
+ if ($config_entity->isTranslatable()) {
+ $translatable_configs[$bundle] = $config_entity;
+ }
+ else {
+ $untranslatable_configs[$bundle] = $config_entity;
+ }
+ }
+ else {
+ // https://www.drupal.org/node/2451657#comment-11462881
+ \Drupal::logger('views')->error(
+ t('A non-existent config entity name returned by FieldStorageConfigInterface::getBundles(): field name: %field, bundle: %bundle',
+ ['%field' => $field_name, '%bundle' => $bundle]
+ ));
+ }
+ }
+
+ // If the field is translatable on all the bundles, there will be a join on
+ // the langcode.
+ if (!empty($translatable_configs) && empty($untranslatable_configs)) {
+ $translation_join_type = 'language';
+ }
+ // If the field is translatable only on certain bundles, there will be a join
+ // on langcode OR bundle name.
+ elseif (!empty($translatable_configs) && !empty($untranslatable_configs)) {
+ foreach ($untranslatable_configs as $config) {
+ $untranslatable_config_bundles[] = $config->getTargetBundle();
+ }
+ $translation_join_type = 'language_bundle';
+ }
+