diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 894d1ae..b39c19d 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -152,13 +152,17 @@ public function getViewsData() { } } - $data[$base_table]['operations'] = array( - 'field' => array( - 'title' => $this->t('Operations links'), - 'help' => $this->t('Provides links to perform entity operations.'), - 'id' => 'entity_operations', - ), - ); + if ($this->entityType->hasListBuilderClass()) { + // The handler for entity operations needs the entity list builder; only + // provide it if there is one. + $data[$base_table]['operations'] = array( + 'field' => array( + 'title' => $this->t('Operations links'), + 'help' => $this->t('Provides links to perform entity operations.'), + 'id' => 'entity_operations', + ), + ); + } // Setup relations to the revisions/property data. if ($data_table) { diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index fb34794..30f551e 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -155,6 +155,30 @@ protected function setupBaseFields(array $base_fields) { } /** + * @covers ::getViewsData + */ + public function testGetViewsDataWithoutEntityOperations() { + // Make sure there is no list builder. The API does not document is + // supports resetting entity handlers, so this might break in the future. + $this->baseEntityType->setListBuilderClass(NULL); + + $data = $this->viewsData->getViewsData(); + + $this->assertArrayNotHasKey('operations', $data[$this->baseEntityType->getBaseTable()]); + } + + /** + * @covers ::getViewsData + */ + public function testGetViewsDataWithEntityOperations() { + $this->baseEntityType->setListBuilderClass('\Drupal\Core\Entity\EntityListBuilder'); + + $data = $this->viewsData->getViewsData(); + + $this->assertSame('entity_operations', $data[$this->baseEntityType->getBaseTable()]['operations']['field']['id']); + } + + /** * Tests base tables. */ public function testBaseTables() {