use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Render\Markup;
+use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\system\ActionConfigEntityInterface;
}
}
-
// Field modules can implement hook_field_views_data() to override the default
// behavior for adding fields.
$module_handler = \Drupal::moduleHandler();
// Sort the field labels by it most used label and return the most used one.
// If the counts are equal, sort by the label to ensure the result is
// deterministic.
- uksort($label_counter, function($a, $b) use ($label_counter) {
+ uksort($label_counter, function ($a, $b) use ($label_counter) {
if ($label_counter[$a] === $label_counter[$b]) {
return strcmp($a, $b);
}
];
}
+ // 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';
+ }
+
// Build the relationships between the field table and the entity tables.
$table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_CURRENT]['alias'];
if ($data_table) {
'field' => 'entity_id',
'extra' => [
['field' => 'deleted', 'value' => 0, 'numeric' => TRUE],
- ['left_field' => 'langcode', 'field' => 'langcode'],
],
];
}
];
}
+ if ($translation_join_type === 'language_bundle') {
+ $data[$table_alias]['table']['join'][$data_table]['join_id'] = 'field_or_language_join';
+ $data[$table_alias]['table']['join'][$data_table]['extra'][] = [
+ 'left_field' => 'langcode',
+ 'field' => 'langcode',
+ ];
+ $data[$table_alias]['table']['join'][$data_table]['extra'][] = [
+ 'field' => 'bundle',
+ 'value' => $untranslatable_config_bundles,
+ ];
+ }
+ elseif ($translation_join_type === 'language') {
+ $data[$table_alias]['table']['join'][$data_table]['extra'][] = [
+ 'left_field' => 'langcode',
+ 'field' => 'langcode',
+ ];
+ }
+
if ($supports_revisions) {
$table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_REVISION]['alias'];
if ($entity_revision_data_table) {
'field' => 'revision_id',
'extra' => [
['field' => 'deleted', 'value' => 0, 'numeric' => TRUE],
- ['left_field' => 'langcode', 'field' => 'langcode'],
],
];
}
],
];
}
+ if ($translation_join_type === 'language_bundle') {
+ $data[$table_alias]['table']['join'][$entity_revision_data_table]['join_id'] = 'field_or_language_join';
+ $data[$table_alias]['table']['join'][$entity_revision_data_table]['extra'][] = [
+ 'left_field' => 'langcode',
+ 'field' => 'langcode',
+ ];
+ $data[$table_alias]['table']['join'][$entity_revision_data_table]['extra'][] = [
+ 'value' => $untranslatable_config_bundles,
+ 'field' => 'bundle',
+ ];
+ }
+ elseif ($translation_join_type === 'language') {
+ $data[$table_alias]['table']['join'][$entity_revision_data_table]['extra'][] = [
+ 'left_field' => 'langcode',
+ 'field' => 'langcode',
+ ];
+ }
}
$group_name = $entity_type->getLabel();