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

8.0.x
Nathaniel Catchpole 2015-11-02 14:24:54 +00:00
parent 6f4690d40d
commit bad2aea4ee
3 changed files with 49 additions and 7 deletions

View File

@ -152,6 +152,9 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
} }
} }
// Entity types must implement a list_builder in order to use Views'
// entity operations field.
if ($this->entityType->hasListBuilderClass()) {
$data[$base_table]['operations'] = array( $data[$base_table]['operations'] = array(
'field' => array( 'field' => array(
'title' => $this->t('Operations links'), 'title' => $this->t('Operations links'),
@ -159,6 +162,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
'id' => 'entity_operations', 'id' => 'entity_operations',
), ),
); );
}
// Setup relations to the revisions/property data. // Setup relations to the revisions/property data.
if ($data_table) { if ($data_table) {

View File

@ -774,6 +774,26 @@ class EntityViewsDataTest extends UnitTestCase {
$this->assertEquals('entity_link_edit', $data['entity_test']['edit_entity_test']['field']['id']); $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. * Tests views data for a string field.
* *

View File

@ -313,3 +313,21 @@ function _views_update_argument_map($displays) {
/** /**
* @} End of "addtogroup updates-8.0.0-beta". * @} 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".
*/