Commit c7cc44ea authored by alexpott's avatar alexpott

Issue #2729325 by yanniboi, Berdir, Xano, dawehner, YesCT: EntityViewsData...

Issue #2729325 by yanniboi, Berdir, Xano, dawehner, YesCT: EntityViewsData adds entity type to multi-value base tables, conflicts with QueryPluginBase::getEntityTableInfo
parent 35a5e6bc
......@@ -285,6 +285,14 @@ public function getEntityTableInfo() {
foreach ((array) $this->view->relationship as $relationship_id => $relationship) {
$table_data = $views_data->get($relationship->definition['base']);
if (isset($table_data['table']['entity type'])) {
// If this is not one of the entity base tables, skip it.
$entity_type = \Drupal::entityTypeManager()->getDefinition($table_data['table']['entity type']);
$entity_base_tables = [$entity_type->getBaseTable(), $entity_type->getDataTable(), $entity_type->getRevisionTable(), $entity_type->getRevisionDataTable()];
if (!in_array($relationship->definition['base'], $entity_base_tables)) {
continue;
}
$entity_tables[$relationship_id . '__' . $relationship->tableAlias] = array(
'base' => $relationship->definition['base'],
'relationship_id' => $relationship_id,
......
......@@ -202,6 +202,12 @@ protected function setupEntityTypes($entities_by_type = [], $entity_revisions_by
'entity revision' => TRUE,
],
]);
$views_data->get('entity_first_field_data')->willReturn([
'table' => [
'entity type' => 'first',
'entity revision' => FALSE,
],
]);
$this->setupViewsData($views_data->reveal());
// Setup the loading of entities and entity revisions.
......@@ -367,6 +373,55 @@ public function testLoadEntitiesWithRelationship() {
$this->assertSame($entities['second'][12], $result[2]->_relationship_entities['entity_second']);
}
/**
* @covers ::loadEntities
* @covers ::assignEntitiesToResult
*/
public function testLoadEntitiesWithNonEntityRelationship() {
// We don't use prophecy, because prophecy enforces methods.
$view = $this->getMockBuilder(ViewExecutable::class)->disableOriginalConstructor()->getMock();
$this->setupViewWithRelationships($view, 'entity_first_field_data');
$view_entity = $this->prophesize(ViewEntityInterface::class);
$view_entity->get('base_table')->willReturn('entity_first');
$view_entity->get('base_field')->willReturn('id');
$view->storage = $view_entity->reveal();
$entities = [
'first' => [
1 => $this->prophesize(EntityInterface::class)->reveal(),
2 => $this->prophesize(EntityInterface::class)->reveal(),
],
];
$entity_type_manager = $this->setupEntityTypes($entities);
$query = new Sql([], 'sql', [], $entity_type_manager->reveal());
$query->view = $view;
$result = [];
$result[] = new ResultRow([
'id' => 1,
]);
$result[] = new ResultRow([
'id' => 2,
]);
$query->addField('entity_first', 'id', 'id');
$query->loadEntities($result);
$entity_information = $query->getEntityTableInfo();
$this->assertSame($entities['first'][1], $result[0]->_entity);
$this->assertSame($entities['first'][2], $result[1]->_entity);
$this->assertEquals([], $result[0]->_relationship_entities);
$this->assertEquals([], $result[1]->_relationship_entities);
// This is an entity table and should be in $entity_information.
$this->assertContains('first', array_keys($entity_information));
// This is not an entity table and should not be in $entity_information.
$this->assertNotContains('entity_first_field_data__entity_first_field_data', array_keys($entity_information));
}
/**
* @covers ::loadEntities
* @covers ::assignEntitiesToResult
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment