diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 4459af4..fa5c36a 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -363,19 +363,11 @@ protected function addEntityLinks(array &$data) { protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterface $field_definition, TableMappingInterface $table_mapping, &$table_data) { // Create a dummy instance to retrieve property definitions. $field_column_mapping = $table_mapping->getColumnNames($field_name); - $field_schema = $this->getFieldStorageDefinitions()[$field_name]->getSchema(); - - $field_definition_type = $field_definition->getType(); - // Add all properties to views table data. We need an entry for each - // column of each field, with the first one given special treatment. - // @todo Introduce concept of the "main" column for a field, rather than - // assuming the first one is the main column. See also what the - // mapSingleFieldViewsData() method does with $first. - $first = TRUE; - foreach ($field_column_mapping as $field_column_name => $schema_field_name) { - $table_data[$schema_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $field_definition_type, $field_column_name, $field_schema['columns'][$field_column_name]['type'], $first, $field_definition); + + // Add an entry for each column of each field into views table data. + foreach ($field_column_mapping as $column_name => $schema_field_name) { + $table_data[$schema_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $column_name, $field_definition); $table_data[$schema_field_name]['entity field'] = $field_name; - $first = FALSE; } } @@ -386,27 +378,24 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf * The table of the field to handle. * @param string $field_name * The machine name of the field being processed. - * @param string $field_type - * The type of field being handled. * @param string $column_name * For fields containing multiple columns, the column name being processed. - * @param string $column_type - * Within the field, the column type being handled. - * @param bool $first - * TRUE if this is the first column within the field. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * * @return array * The modified views data field definition. */ - protected function mapSingleFieldViewsData($table, $field_name, $field_type, $column_name, $column_type, $first, FieldDefinitionInterface $field_definition) { + protected function mapSingleFieldViewsData($table, $field_name, $column_name, FieldDefinitionInterface $field_definition) { $views_field = array(); - // Provide a nicer, less verbose label for the first column within a field. - // @todo Introduce concept of the "main" column for a field, rather than - // assuming the first one is the main column. - if ($first) { + $field_storage_definition = $this->getFieldStorageDefinitions()[$field_name]; + $column_type = $field_storage_definition->getSchema()['columns'][$column_name]['type']; + $field_type = $field_definition->getType(); + $main_property = $field_storage_definition->getMainPropertyName(); + + // The field's main property gets a special treatment. + if ($column_name === $main_property) { $views_field['title'] = $field_definition->getLabel(); } else { diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index 5a70eca..7fc5df0 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -129,6 +129,7 @@ protected function setUp() { $container->set('plugin.manager.field.field_type', $field_type_manager); $container->set('entity.manager', $this->entityManager); $container->set('typed_data_manager', $typed_data_manager); + $container->set('string_translation', $this->translationManager); \Drupal::setContainer($container); }