Problem/Motivation
AuthCodeFunctionalTest fails on Drupal 11.4+ because user_pass_reset_url() is deprecated but there is no working compatibility shim in place.
Proposed resolution
Use DeprecationHelper::backwardsCompatibleCall() to call the new OneTimeAuthentication service on 11.4+ and fall back to user_pass_reset_url() on older versions:
use Drupal\Component\Utility\DeprecationHelper;
use Drupal\user\OneTimeAuthentication;
$reset_url = DeprecationHelper::backwardsCompatibleCall(
\Drupal::VERSION,
'11.4.0',
fn () => \Drupal::service(OneTimeAuthentication::class)->generateOneTimeLoginUrl($new_user)->toString(),
fn () => user_pass_reset_url($new_user),
);
Remaining tasks
- Apply the fix in
tests/src/Functional/AuthCodeFunctionalTest.php
Comments
Comment #3
attilatilman commentedComment #5
pfrillingThe code looks good to me and fixes the deprecation message flagged in the tests.
One note, the CI pipeline will _not_ go green because #3620858: Fix deprecation message strings in Oauth2ScopePluginManagerLegacyTest also needs to merge.
Comment #7
bojan_dev commentedThank you!