From a7c60d669f3a658060ad8a0523c313d706849224 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Mon, 17 Mar 2025 14:09:43 +0000
Subject: [PATCH] =?UTF-8?q?Issue=20#2895933=20by=20boobaa,=20lendude,=20qu?=
 =?UTF-8?q?ietone,=20krzysztof=20doma=C5=84ski,=20smustgrave,=20efpapado:?=
 =?UTF-8?q?=20EntityReverse=20will=20always=20use=20the=20'standard'=20joi?=
 =?UTF-8?q?n=20plugin?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../views/relationship/EntityReverse.php      |  3 +-
 .../Kernel/Plugin/EntityReverseJoinTest.php   | 52 +++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 core/modules/views/tests/src/Kernel/Plugin/EntityReverseJoinTest.php

diff --git a/core/modules/views/src/Plugin/views/relationship/EntityReverse.php b/core/modules/views/src/Plugin/views/relationship/EntityReverse.php
index ce3f08b54370..e7f118b3a74d 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 000000000000..e05daccd4c32
--- /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']);
+  }
+
+}
-- 
GitLab