Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of #2017207: [meta] Complete conversion of users to Entity Field API, this is what #2015123: Expand NodeInterface to provide getters and setters is for nodes.
This is the same patch as #2017207-47: [meta] Complete conversion of users to Entity Field API, just re-uploaded in this issue so that we can commit and then close this, as usual, making the other a meta issue.
Comment | File | Size | Author |
---|---|---|---|
#31 | user-account-interface-2026347-31.patch | 55.88 KB | Berdir |
#31 | user-account-interface-2026347-31-interdiff.txt | 1.7 KB | Berdir |
#28 | user-account-interface-2026347-28.patch | 55.89 KB | Berdir |
#28 | user-account-interface-2026347-28-interdiff.txt | 3.93 KB | Berdir |
#23 | user-account-interface-2026347-23.patch | 57.5 KB | Berdir |
Comments
Comment #1
BerdirTagging.
Comment #2
BerdirComment #3
fubhy CreditAttribution: fubhy commentedYai for this.
missing @param type (string)
Let's add two methods for this and get rid of that $type argument.
The preferred admin language code.
Yeah... Umh, let's really go with two separate methods (one for admin, one for non-admin). :)
Empty line.
Okay, I see where this is coming from now. Still. It's weird. Let's change that.
Comment #4
Gábor HojtsyYeah in core, we have two preferred langcodes, admin and regular. And there are 3 languages assignable to an account in total. There is also the entity language, which is the third. The UI does not expose all 3. If you install Drupal by default, it will only expose the language if language module is enabled. Then the language selector will set the entity language and the preferred language at once. The admin preferred language is only exposed if some language type has it configured (and the user is an admin). It is only used in that case also. So these are all built in properties/behaviours and not extensible as such. So we can have specific methods for them theoretically :)
Comment #5
BerdirSplitted up that method.
Comment #7
BerdirFixed the docblock and killed user_preferred_langcode(), I spent more time on thinking about how to update it's documentation than killing it ;)
Comment #9
fubhy CreditAttribution: fubhy commentedCool. Much cleaner now.
Can we make these return $this? I like it when methods for which a return value makes no sense are chainable.
Comment #10
BerdirMade them do that, although I think it's less frequently used than e.g. query conditions but our coding standards basically say you should do that.
Also fixed the user bc decorator.
Comment #12
BerdirStupid typo.
Comment #13
fubhy CreditAttribution: fubhy commentedGreat. RTBC if green.
Comment #15
BerdirMissed one preferred admin language calls.
Comment #17
Berdir#15: user-account-interface-2026347-15.patch queued for re-testing.
Comment #18
fubhy CreditAttribution: fubhy commentedCool. Back to RTBC.
Comment #19
tim.plunkettHow are label() and getUserName() different?
Missing the rest of the doc.
Comment #20
alexpottBased on #19
Comment #21
BerdirSo.. . I added getUsername() because we need something user_format_name() that doesn't cause a loop as label() -> user_uri_callback() -> user_format_name().
Alternatively, we could kill user_format_name() and inline it. That means we need to move the anonymous logic into the User/UserSession classes.. which I would be fine with.
Opinions?
Comment #22
fubhy CreditAttribution: fubhy commentedYes, discussed this with berdir a few minutes ago and I think it is fine with in-lining that code. Best part about it: Removing user_format_name().
Comment #23
BerdirOk. deprecated user_format_name() and moved the implementation into the two classes. It is now the same as label(), but I think much more meaningful, and better documented for this case.
I think that's a pattern that we want to use for other entity types as well. label() is generic, and if you have any entity and just want whatever it wants to use as it's label, call label(). If you are working with users, getUsername() is easier to understand, if you have a $node, getTitle() is, also, more meaningful and means we can also use it in edit forms and so on, where we don't want it to be alterable.
That does mean we're losing the ability for making it alterable there, but especially in this case, the username already has a specific alter, so an alterable callback is unnecessary.
Anyone disagreeing? :)
Comment #24
fagoSounds good!
Comment #25
tim.plunkettI disagree with having getName/getTitle for each one. Having label() across all entity types is a feature.
I certainly don't want to have to have getNid() getTid() getCid() and go back to remembering which is which.
I'm okay with the inlining, but I still don't want two methods to do the exact same thing. We've worked hard to remove that weird overlap in Views. (Display handlers, anyone?)
Comment #26
msonnabaum CreditAttribution: msonnabaum commentedAgree with #23. It's fine to have a label() method, but it should pass through to a method that's more descriptive.
The getNid() getTid() getCid() example doesn't really work, because you'd just call id(). Those are exposing implementation details, not domain knowledge.
Comment #27
alexpottI agree with @msonnabaum here...
Comment #28
BerdirRe-roll. Fixed up langcode stuff and removed an unrelated comment fix in those negotation test, not sure where they are from, maybe phpstorm fixed that up automatically...
Comment #29
fubhy CreditAttribution: fubhy commentedGreat, RTBC if it comes back green.
Comment #31
Berdirlangcode/id fixes.
Comment #32
ParisLiakos CreditAttribution: ParisLiakos commentedback to rtbc
Comment #33
YesCT CreditAttribution: YesCT commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #34
YesCT CreditAttribution: YesCT commented(tag did not stick. trying again.)
Comment #35
Berdir#31: user-account-interface-2026347-31.patch queued for re-testing.
Comment #36
alexpottCommitted 5a85a56 and pushed to 8.x. Thanks!
I think we need to update the existing change notice and we need to announce the removal of
user_preferred_langcode()
Comment #37
tstoecklerPretty sure this doesn't work as intended, as getPreferred(Admin)Langcode() never returns NULL. Instead it has $default support built-in.
Setting to "needs review" for that.
Comment #38
tstoecklerOops, thought this was "fixed". That was pointless.
Comment #39
BerdirUpdated https://drupal.org/node/1783392, see https://drupal.org/node/1783392/revisions/view/2350726/2763509 and referenced this issue in https://drupal.org/node/2017231 and https://drupal.org/node/1806650.
@tstoeckler: Yes, that looks pretty weird but I'm quite sure that I did not change the behavior here, I just converted a function call to a method. The old function returned the same thing. Can you open a new issue?
Comment #41
scor CreditAttribution: scor commentedFollow up issue: #2112679: getUsername() should return the username getDisplayName() for the formatted user name