From bad2aea4ee47b44e792dec270c52bd9efca855f2 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 2 Nov 2015 14:24:54 +0000 Subject: [PATCH] Issue #2491875 by joachim, xjm, Xano, alexpott: EntityViewsData adds Operations links to all entities, which won't work if the entity type has no list builder, leading to WSOD on some views --- core/modules/views/src/EntityViewsData.php | 18 ++++++++++------- .../tests/src/Unit/EntityViewsDataTest.php | 20 +++++++++++++++++++ core/modules/views/views.install | 18 +++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index a9bc03e51ab..20692719b8b 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -152,13 +152,17 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac } } - $data[$base_table]['operations'] = array( - 'field' => array( - 'title' => $this->t('Operations links'), - 'help' => $this->t('Provides links to perform entity operations.'), - 'id' => 'entity_operations', - ), - ); + // Entity types must implement a list_builder in order to use Views' + // entity operations field. + if ($this->entityType->hasListBuilderClass()) { + $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 9a65d6e51b3..dfdc0bd4e46 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -774,6 +774,26 @@ class EntityViewsDataTest extends UnitTestCase { $this->assertEquals('entity_link_edit', $data['entity_test']['edit_entity_test']['field']['id']); } + /** + * @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 views data for a string field. * diff --git a/core/modules/views/views.install b/core/modules/views/views.install index fd49684393d..345b56984a3 100644 --- a/core/modules/views/views.install +++ b/core/modules/views/views.install @@ -313,3 +313,21 @@ function _views_update_argument_map($displays) { /** * @} End of "addtogroup updates-8.0.0-beta". */ + +/** + * @addtogroup updates-8.0.0-rc + * @{ + */ + +/** + * Clear caches to fix entity operations field. + */ +function views_update_8003() { + // Empty update to cause a cache flush so that views data is rebuilt. Entity + // types that don't implement a list builder cannot have the entity operations + // field. +} + +/** + * @} End of "addtogroup updates-8.0.0-rc". + */