From 51e7a08352a0df53a87d4cfa42d22a508085a2db Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 9 Jul 2022 15:17:23 +0100
Subject: [PATCH] Issue #3137119 by munish.kumar, johnwebdev, Jaypan, jungle,
 xjm, catch: User::setExistingPassword() does not return $this for chaining

---
 core/modules/user/src/Entity/User.php                |  1 +
 .../modules/user/tests/src/Kernel/UserEntityTest.php | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php
index dcbebbf81ff8..1e41b11efceb 100644
--- a/core/modules/user/src/Entity/User.php
+++ b/core/modules/user/src/Entity/User.php
@@ -398,6 +398,7 @@ public function setUsername($username) {
    */
   public function setExistingPassword($password) {
     $this->get('pass')->existing = $password;
+    return $this;
   }
 
   /**
diff --git a/core/modules/user/tests/src/Kernel/UserEntityTest.php b/core/modules/user/tests/src/Kernel/UserEntityTest.php
index cf711ea4ca56..94f911cfa90b 100644
--- a/core/modules/user/tests/src/Kernel/UserEntityTest.php
+++ b/core/modules/user/tests/src/Kernel/UserEntityTest.php
@@ -91,4 +91,16 @@ public function testUserValidation() {
     $this->assertFalse((bool) $violations->count());
   }
 
+  /**
+   * Tests that ::existingPassword can be used for chaining.
+   */
+  public function testChainExistingPasswordMethod() {
+    /** @var \Drupal\user\Entity\User $user */
+    $user = User::create([
+      'name' => $this->randomMachineName(),
+    ]);
+    $user = $user->setExistingPassword('existing_pass');
+    $this->assertInstanceOf(User::class, $user);
+  }
+
 }
-- 
GitLab