Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
user.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Nov 2025 at 21:59 UTC
Updated:
7 Apr 2026 at 20:40 UTC
Jump to comment: Most recent
I'm currently reviewing all the functions in user.module, with the goal to eventually remove the .module file completely.
user_load_by_mail & user_load_by_name are very basic functions that can just be deprecated without replacement.
Look at the functions
See they are very basic.
Deprecate the functions. We could add helpers to UserInterface but I don't think thats required.
Deprecate the functions.
N/A
N/A
user_load_by_mail & user_load_by_name are deprecated.
N/A
TODO: A CR will be required if we do this.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
santanu mondal commentedComment #4
santanu mondal commentedComment #5
astonvictor commentedAs I can see, the pipeline has failed.
I also found a comment with a link to the current
@see https://www.drupal.org/node/3555670page. As I understand, we use links for CR and not for issues.+
@deprecated in drupal:11.1.0- should be 11.3Comment #6
astonvictor commentedIt also requires replacing all calls in core modules (without removing functions for now).
Comment #7
santanu mondal commentedHi @astonvictor i have to create the CR? in drupal.org??
Comment #8
astonvictor commentedit should be possible to use https://www.drupal.org/node/add/changenotice?field_project=3060
Comment #9
santanu mondal commentedHi @astonvictor can you help me to solve the phpunit pipeline problem??
Comment #10
santanu mondal commentedComment #11
smustgrave commentedIt's not getting passed phpstan, may need to update the baseline.
Comment #12
santanu mondal commentedI have solve the phpstan error.
Comment #13
santanu mondal commentedComment #14
santanu mondal commentedComment #15
santanu mondal commentedFor get the active user.
Comment #16
volegerHi @santanu mondal, I left a review comment.
Comment #17
volegerAdded more review coments
Comment #20
samitk commentedI have created a new PR against 11.x and incorporated all the PR review suggestions.
Please review.
https://git.drupalcode.org/project/drupal/-/merge_requests/14455Comment #25
dcam commentedComment #27
dcam commentedI probably edited this one too much to be eligible to review it now. During the process of creating the new branch I stripped out all of the unrelated and unnecessary changes. I also undid a line wrap to a ternary statement. As far as I can tell, we don't have coding standards for line-wrapping ternary statements, but we almost universally indent wrapped statements after the first line. In this case there was no indentation. I decided to remove the line wrap entirely because I didn't think it was necessary.
Comment #28
danielvezaNice, changes are pretty much what I would expect to see. Tests are green, I think this is ready for RTBC
Comment #29
nicxvan commentedSorry there is a mismatch in deprecation versions on one.
Did we get confirmation of deprecation without replacement from user module maintainers? @kristiaanvandeneynde or @moshe weitzman
Comment #30
berdirYes, I've been pondering about that too. There are hundreds of usages of those two functions in contrib, and and loadByProperties() isn't the greatest API IMHO:
https://git.drupalcode.org/search?group_id=2&scope=blobs&search=%22user_...
Either we'd add something like User::loadByName(), but we probably want to not promote more static methods, the other option is UserRepository service like we're adding in #2536594: Add a FilterFormatRepository providing methods to load filter formats and have other examples too, I think that's worth considering.
Comment #31
moshe weitzman commentedI prefer removal of the functions without replacement. I personally dont think any new service is needed.
Comment #32
kristiaanvandeneyndeIf we were doing something special in user_load_by_mail() and user_load_by_name() regarding optimization, then this wouldn't be as clear cut. But, as it stands, it's a simple wrapper around loadByProperties() already. Removing the functions will also make testing and juggling dependencies easier as the classes that used to call it can now use their own copy of the entity type manager service to get the user storage.
So +1 on removal without replacement. It's time to rip the band-aid off for this one.
Comment #33
kristiaanvandeneyndeMaybe we can fix this by introducing #3569814: Introduce EntityRepositoryInterface::loadUniqueByProperties to reduce boilerplate, increase stability and please phpstan. and then changing the deprecation notice to point to that instead?
Comment #34
joachim commentedWe should maybe wait until that other issue gets in, so that the CR can tell people about the new API.
Comment #35
berdirNot sure that's necessary, especially for contrib. The good thing about the current "replacement" is that it's not new. It's easy to just convert the calls and it works in any supported and non-supported core version 8.0+. Having a replacement, either here or the proposed API in #33 would require for contrib to do the usual DeprecationHelper/method_exists/version_compare BC dance, which results, at least for now, in more code/complexity than the existing API that's used here.
Comment #36
kristiaanvandeneyndeTrue, if you already update your module to take care of this deprecation and use the new method, then that's an implicit core version bump. If you use the loadByProperties() and reset() combo, then you're good to go. We could try and add a rule later on that detects said combo and advises to use the new method.
Then again, we have full reign over core. So if we do wait for the other issue to land, at least we could already clean up the calls in core with the new method.
We could update the CR to mention both options, clearly stating the implication of using the newer approach.
Comment #38
alexpottI think given the widespread usage of user_load_by_ functions in contrib we're too late to deprecate this for 12.0.0 even though the replacement is already possible. Discussed with @catch and we agreed that the deprecation should be for Drupal 13. See https://git.drupalcode.org/search?group_id=2&scope=blobs&search=user_loa...
Comment #39
volegerUpdated MR to address #38
Comment #40
nod_Updating search links:
#30: user_load_by_name($
#38: user_load_by_.*($
Comment #41
berdirThe only change since this was set back from RTBC is the deprecation version (and merges), still looks OK.
Comment #42
sivaji_ganesh_jojodae commentedThe MR has git conflict issue it couldn't be rebased from UI.
Comment #43
longwaveNeeds rebase.
Comment #44
dcam commentedI was able to update the fork in the browser UI. I don't know why it still reports that the MR still needs to be rebased. It doesn't. I pulled it to my local and tried to merge main, but Git said that it's already up-to-date. So I think everything is fine and GitLab is just crazy.
Comment #48
godotislateCommitted 9a9ada0 and pushed to main, and committed 9151865 and pushed to 11.x. Thanks!
Comment #50
nicxvan commentedRealizing I never linked the conversation in slack https://drupal.slack.com/archives/C079NQPQUEN/p1769449447565259
I think it meets the bar for credit, but I forgot to mention it:
@lleber and @joachim also participated in slack (@moshe, @berdir, and @kristiaan already received credit for direct contribution)
Comment #51
godotislateCredit updated per #50.
Comment #52
nicxvan commentedThanks!
Comment #54
catchJust tried to commit a different issue and ran into a phpstan error on the deprecation.
I've committed https://git.drupalcode.org/project/drupal/-/commit/2d88383f7e08c89a07a56... to workaround this, but I'm wondering if that got added between the last pipeline run here and the commit. We might need a quick follow-up to remove the usage and baseline entry?
Comment #56
longwave@catch's commit broke main, I think maybe due to a rogue file in his local checkout? The job was failing so I reverted that commit and now it's green again, tentatively marking this fixed again.
Comment #58
catchYep I had a rogue file in my local checkout (the only rogue file), and it previously hadn't caused any issues, but due to having user_load_by_name() in it, messed up phpstan. Mystery solved at least (and deleted the file).