diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index dcbebbf81ff835a5ad68fcdeee75a28031a729f0..1e41b11efcebc5c26b29644a939426e967bbc17a 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 cf711ea4ca56f08bc59196fec78a092a1861502c..94f911cfa90b996a63ec55873a9c354e93a85e11 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); + } + }