diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 32323f2..de13538 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -154,11 +154,9 @@ public function getViewsData() { 'field' => $base_field, 'type' => 'INNER' ]; - $data[$data_table]['table']['entity type'] = $this->entityType->id(); $data[$data_table]['table']['group'] = $this->entityType->getLabel(); } if ($revision_table) { - $data[$revision_table]['table']['entity type'] = $this->entityType->id(); $data[$revision_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]); $data[$revision_table]['table']['base'] = array( 'field' => $revision_field, @@ -172,7 +170,6 @@ public function getViewsData() { ); if ($revision_data_table) { - $data[$revision_data_table]['table']['entity type'] = $this->entityType->id(); $data[$revision_data_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]); $data[$revision_data_table]['table']['join'][$revision_table] = array( @@ -240,6 +237,8 @@ protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterf foreach ($field_column_mapping as $field_column_name => $schema_field_name) { $views_field_name = ($multiple) ? $field_name . '__' . $field_column_name : $field_name; $table_data[$views_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $field_definition_type, $field_column_name, $field_schema['columns'][$field_column_name]['type'], $first, $field_definition); + + $table_data[$views_field_name]['entity field'] = $field_name; $first = FALSE; } } diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index 146c6a8..ac7abda 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -91,7 +91,7 @@ public function getHandler($item, $override = NULL) { if (isset($data[$field][$this->handlerType])) { $definition = $data[$field][$this->handlerType]; - foreach (array('group', 'title', 'title short', 'help', 'real field', 'real table') as $key) { + foreach (array('group', 'title', 'title short', 'help', 'real field', 'real table', 'entity field') as $key) { if (!isset($definition[$key])) { // First check the field level. if (!empty($data[$field][$key])) { diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index 3199a51..f3ef66f 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -338,19 +338,29 @@ public function testBaseTableFields() { $data = $this->viewsData->getViewsData(); $this->assertNumericField($data['entity_test']['id']); + $this->assertField($data['entity_test']['id'], 'id'); $this->assertUuidField($data['entity_test']['uuid']); + $this->assertField($data['entity_test']['uuid'], 'uuid'); $this->assertStringField($data['entity_test']['type']); + $this->assertEquals('type', $data['entity_test']['type']['entity field']); $this->assertLanguageField($data['entity_test']['langcode']); + $this->assertField($data['entity_test']['langcode'], 'langcode'); $this->assertEquals('Original language', $data['entity_test']['langcode']['title']); $this->assertStringField($data['entity_test']['name']); + $this->assertField($data['entity_test']['name'], 'name'); $this->assertLongTextField($data['entity_test'], 'description'); + $this->assertField($data['entity_test']['description__value'], 'description'); + $this->assertField($data['entity_test']['description__format'], 'description'); $this->assertUriField($data['entity_test']['homepage']); + $this->assertField($data['entity_test']['homepage'], 'homepage'); $this->assertEntityReferenceField($data['entity_test']['user_id']); + $this->assertField($data['entity_test']['user_id'], 'user_id'); + $relationship = $data['entity_test']['user_id']['relationship']; $this->assertEquals('users', $relationship['base']); $this->assertEquals('uid', $relationship['base field']); @@ -422,12 +432,16 @@ public function testDataTableFields() { // Check the base fields. $this->assertNumericField($data['entity_test_mul']['id']); + $this->assertField($data['entity_test_mul']['id'], 'id'); $this->assertUuidField($data['entity_test_mul']['uuid']); + $this->assertField($data['entity_test_mul']['uuid'], 'uuid'); $this->assertBundleField($data['entity_test_mul']['type']); + $this->assertField($data['entity_test_mul']['type'], 'type'); $this->assertFalse(isset($data['entity_test_mul']['type']['relationship'])); $this->assertLanguageField($data['entity_test_mul']['langcode']); + $this->assertField($data['entity_test_mul']['langcode'], 'langcode'); // Also ensure that field_data only fields don't appear on the base table. $this->assertFalse(isset($data['entity_test_mul']['name'])); $this->assertFalse(isset($data['entity_test_mul']['description'])); @@ -438,17 +452,24 @@ public function testDataTableFields() { // Check the data fields. $this->assertNumericField($data['entity_test_mul_property_data']['id']); + $this->assertField($data['entity_test_mul_property_data']['id'], 'id'); $this->assertLanguageField($data['entity_test_mul_property_data']['langcode']); + $this->assertField($data['entity_test_mul_property_data']['langcode'], 'langcode'); $this->assertEquals('Translation language', $data['entity_test_mul_property_data']['langcode']['title']); $this->assertStringField($data['entity_test_mul_property_data']['name']); + $this->assertField($data['entity_test_mul_property_data']['name'], 'name'); $this->assertLongTextField($data['entity_test_mul_property_data'], 'description'); + $this->assertField($data['entity_test_mul_property_data']['description__value'], 'description'); + $this->assertField($data['entity_test_mul_property_data']['description__format'], 'description'); $this->assertUriField($data['entity_test_mul_property_data']['homepage']); + $this->assertField($data['entity_test_mul_property_data']['homepage'], 'homepage'); $this->assertEntityReferenceField($data['entity_test_mul_property_data']['user_id']); + $this->assertField($data['entity_test_mul_property_data']['user_id'], 'user_id'); $relationship = $data['entity_test_mul_property_data']['user_id']['relationship']; $this->assertEquals('users', $relationship['base']); $this->assertEquals('uid', $relationship['base field']); @@ -509,9 +530,13 @@ public function testRevisionTableFields() { // Check the base fields. $this->assertNumericField($data['entity_test_mulrev']['id']); + $this->assertField($data['entity_test_mulrev']['id'], 'id'); $this->assertNumericField($data['entity_test_mulrev']['revision_id']); + $this->assertField($data['entity_test_mulrev']['revision_id'], 'revision_id'); $this->assertUuidField($data['entity_test_mulrev']['uuid']); + $this->assertField($data['entity_test_mulrev']['uuid'], 'uuid'); $this->assertStringField($data['entity_test_mulrev']['type']); + $this->assertField($data['entity_test_mulrev']['type'], 'type'); // Also ensure that field_data only fields don't appear on the base table. $this->assertFalse(isset($data['entity_test_mulrev']['name'])); @@ -524,9 +549,12 @@ public function testRevisionTableFields() { // Check the revision fields. $this->assertNumericField($data['entity_test_mulrev_revision']['id']); + $this->assertField($data['entity_test_mulrev_revision']['id'], 'id'); $this->assertNumericField($data['entity_test_mulrev_revision']['revision_id']); + $this->assertField($data['entity_test_mulrev_revision']['revision_id'], 'revision_id'); $this->assertLanguageField($data['entity_test_mulrev_revision']['langcode']); + $this->assertField($data['entity_test_mulrev_revision']['langcode'], 'langcode'); $this->assertEquals('Original language', $data['entity_test_mulrev_revision']['langcode']['title']); // Also ensure that field_data only fields don't appear on the revision table. @@ -539,36 +567,62 @@ public function testRevisionTableFields() { // Check the data fields. $this->assertNumericField($data['entity_test_mulrev_property_data']['id']); + $this->assertField($data['entity_test_mulrev_property_data']['id'], 'id'); $this->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']); + $this->assertField($data['entity_test_mulrev_property_data']['langcode'], 'langcode'); $this->assertStringField($data['entity_test_mulrev_property_data']['name']); + $this->assertField($data['entity_test_mulrev_property_data']['name'], 'name'); $this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description'); + $this->assertField($data['entity_test_mulrev_property_data']['description__value'], 'description'); + $this->assertField($data['entity_test_mulrev_property_data']['description__format'], 'description'); $this->assertUriField($data['entity_test_mulrev_property_data']['homepage']); + $this->assertField($data['entity_test_mulrev_property_data']['homepage'], 'homepage'); $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']); + $this->assertField($data['entity_test_mulrev_property_data']['user_id'], 'user_id'); $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship']; $this->assertEquals('users', $relationship['base']); $this->assertEquals('uid', $relationship['base field']); // Check the property data fields. $this->assertNumericField($data['entity_test_mulrev_property_revision']['id']); + $this->assertField($data['entity_test_mulrev_property_revision']['id'], 'id'); $this->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']); + $this->assertField($data['entity_test_mulrev_property_revision']['langcode'], 'langcode'); $this->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']); $this->assertStringField($data['entity_test_mulrev_property_revision']['name']); + $this->assertField($data['entity_test_mulrev_property_revision']['name'], 'name'); $this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description'); + $this->assertField($data['entity_test_mulrev_property_revision']['description__value'], 'description'); + $this->assertField($data['entity_test_mulrev_property_revision']['description__format'], 'description'); $this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']); + $this->assertField($data['entity_test_mulrev_property_revision']['homepage'], 'homepage'); $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']); + $this->assertField($data['entity_test_mulrev_property_revision']['user_id'], 'user_id'); $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship']; $this->assertEquals('users', $relationship['base']); $this->assertEquals('uid', $relationship['base field']); } /** + * Tests generic stuff per field. + * + * @param array $data + * The views data to check. + * @param string $field_name + * The entity field name. + */ + protected function assertField($data, $field_name) { + $this->assertEquals($field_name, $data['entity field']); + } + + /** * Tests views data for a string field. * * @param $data