Skip to content

Commit 043a10a

Browse files
author
catch
committed
Issue #2895933 by boobaa, lendude, quietone, krzysztof domański, smustgrave, efpapado: EntityReverse will always use the 'standard' join plugin
1 parent ef24b0b commit 043a10a

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

modules/views/src/Plugin/views/relationship/EntityReverse.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function query() {
6464
// field, using the base table's id field to the field's column.
6565
$views_data = Views::viewsData()->get($this->table);
6666
$left_field = $views_data['table']['base']['field'];
67+
$id = !empty($this->definition['join_id']) ? $this->definition['join_id'] : 'standard';
6768

6869
$first = [
6970
'left_table' => $this->tableAlias,
@@ -98,7 +99,7 @@ public function query() {
9899
$second['type'] = 'INNER';
99100
}
100101

101-
$second_join = $this->joinManager->createInstance('standard', $second);
102+
$second_join = $this->joinManager->createInstance($id, $second);
102103
$second_join->adjusted = TRUE;
103104

104105
// Use a short alias for this:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\Tests\views\Kernel\Plugin;
6+
7+
use Drupal\views\Views;
8+
use Drupal\views_test_data\Plugin\views\join\JoinTest;
9+
10+
/**
11+
* Tests the EntityReverse join plugin.
12+
*
13+
* @group views
14+
* @see \Drupal\views\Plugin\views\relationship\EntityReverse
15+
*/
16+
class EntityReverseJoinTest extends RelationshipJoinTestBase {
17+
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public static $testViews = ['test_view'];
22+
23+
/**
24+
* Tests that the EntityReverse plugin loads the correct join plugin.
25+
*/
26+
public function testJoinThroughRelationship(): void {
27+
$relationship_manager = $this->container->get('plugin.manager.views.relationship');
28+
// Setup a simple join and test the result sql.
29+
$view = Views::getView('test_view');
30+
$view->initDisplay();
31+
$view->initQuery();
32+
33+
$configuration = [
34+
'id' => 'entity_reverse',
35+
'base' => 'users_field_data',
36+
'table' => 'users_field_data',
37+
'field table' => 'users_field_data',
38+
'field field' => 'uid',
39+
'base field' => 'uid',
40+
'field_name' => 'uid',
41+
'join_id' => 'join_test',
42+
];
43+
44+
$relationship = $relationship_manager->createInstance('entity_reverse', $configuration);
45+
$relationship->tableAlias = 'users_field_data';
46+
$relationship->table = 'users_field_data';
47+
$relationship->query = $view->getQuery();
48+
$relationship->query();
49+
$this->assertInstanceOf(JoinTest::class, $relationship->query->getTableQueue()[$relationship->alias]['join']);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)