diff --git a/core/modules/node/src/NodeViewsData.php b/core/modules/node/src/NodeViewsData.php index 202acc9..3a19428 100644 --- a/core/modules/node/src/NodeViewsData.php +++ b/core/modules/node/src/NodeViewsData.php @@ -63,9 +63,6 @@ public function getViewsData() { 'field' => array( 'id' => 'node_type', ), - 'filter' => array( - 'id' => 'bundle', - ), 'argument' => array( 'id' => 'node_type', ), diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index cc89524..9c7574b 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -7,7 +7,7 @@ namespace Drupal\views; -use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\Core\Entity\EntityHandlerInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; @@ -22,7 +22,7 @@ /** * Provides generic views integration for entities. */ -class EntityViewsData implements EntityControllerInterface, EntityViewsDataInterface { +class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterface { use StringTranslationTrait; @@ -97,7 +97,7 @@ function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, - $container->get('entity.manager')->getController($entity_type->id(), 'storage'), + $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('entity.manager'), $container->get('module_handler'), $container->get('string_translation'), @@ -364,6 +364,14 @@ protected function processViewsDataForLanguage($table, $field_name, array &$view } } + protected function processViewsDataForString($table, $field_name, array &$views_field) { + if ($field_name == $this->entityType->getKey('bundle')) { + // @todo Use the other bundle handlers, once + // https://www.drupal.org/node/2322949 is in. + $views_field['filter']['id'] = 'bundle'; + } + } + /** * Gets the table of an entity type to be used as base table in views. * diff --git a/core/modules/views/tests/Drupal/views/Tests/EntityViewsDataTest.php b/core/modules/views/tests/Drupal/views/Tests/EntityViewsDataTest.php index 7bbea2f..7e01256 100644 --- a/core/modules/views/tests/Drupal/views/Tests/EntityViewsDataTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/EntityViewsDataTest.php @@ -302,7 +302,9 @@ public function testDataTableFields() { $entity_type = $this->baseEntityType ->set('data_table', 'entity_test_mul_property_data') ->set('base_table', 'entity_test_mul') - ->set('id', 'entity_test_mul'); + ->set('id', 'entity_test_mul') + ->setKey('bundle', 'type') + ; $base_field_definitions = EntityTestMul::baseFieldDefinitions($this->baseEntityType); $this->entityManager->expects($this->once()) ->method('getBaseFieldDefinitions') @@ -350,7 +352,7 @@ public function testDataTableFields() { // Check the base fields. $this->assertNumericField($data['entity_test_mul']['id']); $this->assertUuidField($data['entity_test_mul']['uuid']); - $this->assertStringField($data['entity_test_mul']['type']); + $this->assertBundleField($data['entity_test_mul']['type']); $this->assertLanguageField($data['entity_test_mul']['langcode']); // Also ensure that field_data only fields don't appear on the base table. $this->assertFalse(isset($data['entity_test_mul']['name'])); @@ -539,6 +541,16 @@ protected function assertEntityReferenceField($data) { } /** + * Tests views data for a bundle field. + */ + protected function assertBundleField($data) { + $this->assertEquals('standard', $data['field']['id']); + $this->assertEquals('bundle', $data['filter']['id']); + $this->assertEquals('string', $data['argument']['id']); + $this->assertEquals('standard', $data['sort']['id']); + } + + /** * Returns entity info for the user entity. * * @return array