diff --git a/core/modules/views/src/Plugin/views/relationship/EntityReverse.php b/core/modules/views/src/Plugin/views/relationship/EntityReverse.php index ce3f08b54370c1b8cc8ca4c23868454841ec0e22..e7f118b3a74d4d22b2ad527a165afca513f31cbc 100644 --- a/core/modules/views/src/Plugin/views/relationship/EntityReverse.php +++ b/core/modules/views/src/Plugin/views/relationship/EntityReverse.php @@ -64,6 +64,7 @@ public function query() { // field, using the base table's id field to the field's column. $views_data = Views::viewsData()->get($this->table); $left_field = $views_data['table']['base']['field']; + $id = !empty($this->definition['join_id']) ? $this->definition['join_id'] : 'standard'; $first = [ 'left_table' => $this->tableAlias, @@ -98,7 +99,7 @@ public function query() { $second['type'] = 'INNER'; } - $second_join = $this->joinManager->createInstance('standard', $second); + $second_join = $this->joinManager->createInstance($id, $second); $second_join->adjusted = TRUE; // Use a short alias for this: diff --git a/core/modules/views/tests/src/Kernel/Plugin/EntityReverseJoinTest.php b/core/modules/views/tests/src/Kernel/Plugin/EntityReverseJoinTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e05daccd4c3224890b6c46f3b4bfef59d3fa9012 --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Plugin/EntityReverseJoinTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\views\Kernel\Plugin; + +use Drupal\views\Views; +use Drupal\views_test_data\Plugin\views\join\JoinTest; + +/** + * Tests the EntityReverse join plugin. + * + * @group views + * @see \Drupal\views\Plugin\views\relationship\EntityReverse + */ +class EntityReverseJoinTest extends RelationshipJoinTestBase { + + /** + * {@inheritdoc} + */ + public static $testViews = ['test_view']; + + /** + * Tests that the EntityReverse plugin loads the correct join plugin. + */ + public function testJoinThroughRelationship(): void { + $relationship_manager = $this->container->get('plugin.manager.views.relationship'); + // Setup a simple join and test the result sql. + $view = Views::getView('test_view'); + $view->initDisplay(); + $view->initQuery(); + + $configuration = [ + 'id' => 'entity_reverse', + 'base' => 'users_field_data', + 'table' => 'users_field_data', + 'field table' => 'users_field_data', + 'field field' => 'uid', + 'base field' => 'uid', + 'field_name' => 'uid', + 'join_id' => 'join_test', + ]; + + $relationship = $relationship_manager->createInstance('entity_reverse', $configuration); + $relationship->tableAlias = 'users_field_data'; + $relationship->table = 'users_field_data'; + $relationship->query = $view->getQuery(); + $relationship->query(); + $this->assertInstanceOf(JoinTest::class, $relationship->query->getTableQueue()[$relationship->alias]['join']); + } + +}