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.
Two notable functions that should be moved to user.module:
format_username (which currently lives in includes/common.inc)
theme_username (includes/theme.inc)
Comment | File | Size | Author |
---|---|---|---|
#48 | 1227942-48.patch | 18.45 KB | xjm |
#48 | interdiff.txt | 631 bytes | xjm |
#45 | 1227942-45.patch | 18.45 KB | tstoeckler |
#43 | 1227942.patch | 17.79 KB | RobLoach |
#40 | 1227942_0.patch | 16.81 KB | RobLoach |
Comments
Comment #1
cweagansFirst patch.
Before this is committed, I think it would be good to rename the theme function to theme_user_name to be consistent with the other user theme functions.
Comment #2
marcingy CreditAttribution: marcingy commentedThis is a task not a bug.
Comment #3
sunLooks like you forgot these?
1 days to next Drupal core point release.
Comment #4
cweagansYou're right! Completely skipped over those. New patch attached.
Comment #5
cweagansI think the question of changing the theme function to theme_user_name is better left to another issue.
Comment #6
suneek, patch serials are a wonky to review... can you roll a single?
I'd be happy with this, but I'd like @catch to RTBC it.
Comment #7
cweagansSingle patch attached. git format-patch is really nice, but I can't figure out how to get it to not produce those serial patches, so this is rolled with git diff.
Comment #9
cweagans#7: 1227942-7-move-user-functions.patch queued for re-testing.
Comment #11
cweagansHrm, anybody have any idea why that patch will not apply?
Comment #12
joachim CreditAttribution: joachim commentedI don't know why it doesn't apply, but it doesn't:
Comment #13
Dave ReidThe patch is reversed - its moving code from user.module to includes/common.inc.
Comment #14
cweagansAh, so it is. That was weird. New patch.
Comment #15
RobLoachShot in the dark with the new /core file structure?
Comment #16
RobLoachThe testing bot likes it, and it really helps with cleaning up common.inc and theme.inc. Applied, cleared cache... Usernames are still being displayed correctly. I'm marking this one RTBC.
Comment #17
cweagansCan this be backported to 7.x? Is it considered an API break? The theme functions still exist...they're just moved around.
Comment #18
marcingy CreditAttribution: marcingy commented+1 on the rtbc as Rob Loach shouldn't really be rbtc'ing his own patch!
Comment #19
joachim CreditAttribution: joachim commented> Can this be backported to 7.x? Is it considered an API break? The theme functions still exist...they're just moved around.
They're moved from essential include files to a required module... nobody's site will break and theme functions will continue to work. So doesn't sound like an API break to me.
Comment #20
cweagansI think the patch in #14 will apply to 7.x, and #15 is for 8.x.
Comment #21
catchVery nice. Committed/pushed to 8.x. Thanks!
Comment #22
catchWell I was a bit trigger happy.
Now we have format_username() in user.module, which completely violates coding standards for namespacing of functions.
This issue is short so let's do the follow-up here.
Comment #23
cweagansI'd like to see about backporting #14 to 7.x, but I'm not sure if it's going to be allowed due to the namespace issue.
First pass at renaming function in 8.x.
Comment #24
RobLoachYeah, let's move it to user.module too.
Comment #26
RobLoachWhoops, missed one.
Comment #28
RobLoachSun also suggested
user_format_name()
to avoid the duplicate "user" :-) .Comment #29
RobLoachComment #31
RobLoachWow, what is wrong with me? #PatchFail
What are your thoughts on somehow merging
user_label()
anduser_format_name()
? Maybe switching the "label callback" arguments around so that the$entity
is first and$entity_type
defaults to "user"?Comment #32
cweagansI think we should leave user_label() and user_format_name() separate - calling user_label() all over the place doesn't make a lot of sense to me because it's not immediately clear what the function does. user_format_name() is pretty self explanatory.
Comment #33
RobLoachLike this... It's still
user_format_name()
, but we save ourselves from having to define two functions.Comment #34
RobLoachMissed one test...
Comment #35
cweagansThe function signatures are a bit different, though:
`function user_format_name($account, $entity_type = 'user')`
vs
`function user_label($entity_type, $entity)`
The arguments are reversed, and I *really* don't want to have to call user_format_name('user', $account) all the time =P
Comment #36
RobLoachI reversed the argument order in the label callback function. So it becomes
entity_label($entity, $entity_type)
. This meansuser_format_name($account)
works as the$entity_type
just defaults to "user".Comment #37
tstoecklerHmm... we specifically chose that parameter order in #1096446: entity_label() is not passing along the $entity_type parameter because "$entity_type, $entity" is the standard in D7/8. Sadly it's not 100% consistent over the place, but in general I think we should standardize on that. Also, the whole debate will become obsolete when #1184944: Make entities classed objects, introduce CRUD support lands, so I'm not sure it would make sense to switch things around just before that again.
Comment #38
sunPlease leave that entity_label() discussion out of this issue. You may want to search the queue for entity system, $entity_type, and entity_label() related discussions.
Looks like #31 is RTBC. Can someone confirm?
Re-uploading that patch to prevent confusion wouldn't hurt either.
Comment #39
Dave ReidHrm, now we have a mismatch with the alter hook. Before it was format_username() and hook_username_alter(). Now we would have user_format_name() and hook_username_alter(). I'm not really happy with the names of those two diverging as well.
Comment #40
RobLoachDeal!
Personally, I think the label callback arguments make more sense as
entity_label($entity, $entity_type)
, but I suppose that's for another issue, like sun suggested.#1184944: Make entities classed objects, introduce CRUD support looks like a pretty awesome issue though!!! I'll get involved over there. Thanks for the link.
Maybe
hook_user_name_alter()
?.... Or,user_format_name()
might live nicely besidehook_user_format_name_alter()
?Comment #41
xjmSo, looks like:
format_username()
touser_format_name()
.hook_user_format_name_alter()
?See also: #1361228: Make the user entity a classed object.
Comment #42
tstoecklerSince we are already changing this, the function should be appended by "()" for it to be linked on api.drupal.org
I agree with #41 on the alter hook.
-11 days to next Drupal core point release.
Comment #43
RobLoachWe could get rid of the function entirely if we change the parameter order of entity_label(), but that's a discussion for another issue. I'll hopefully get around to putting together the follow up issue soon. Maybe in the one xjm mentioned #1361228: Make the user entity a classed object. Thanks!
Yup!
Sounds good! Let's move that into user.api.php too.
Good catch.
Comment #44
RobLoachComment #45
tstoecklerOne occurence of format_username() in the documentation for t() was missed.
This one should fix that.
Comment #46
xjmApplied the patch and checked:
No results, so looks like we got everything.
This is SO close to RTBC, except for one eensy tiny thing....
This is over 80 chars and so we should wrap the function to the next line.
Comment #47
xjmAw heck I will just fix it and RTBC anyway.
Comment #48
xjm* xjm begs forgiveness
Comment #49
xjmTagging.
Comment #50
sunFeel free to disagree and call me nuts, but shouldn't this be $account->label() now or very very soonish?
Comment #51
tstoecklerRe #50: Yes, that's correct.
Because of the parameter order thing, we don't use user_format_name() directly as label callback, but once we have
$user = entity_create('user', array());
> the whole $entity_type thing is gone, and we will call$user->label();
. (Strictly speaking, we could already change all those calls toentity_label('user', $user);
which would pretty much be the same thing.)For now, though,
Entity::save()
simply calls the label callback, so we would still need this function (or move it directly touser_label()
). We could also overrideEntity::save()
withUser::save()
, which would then move the code directly into the class, but I don't think that's part of #1361228: Make the user entity a classed object initially.I also don't know (but I don't think so) if that issue handles
global $user;
, for which we also need this function.So either way, I think this is a step in the right direction, and it shouldn't conflict with making
$user
a classed object (I think :) ...).Comment #52
sungosh... apparently I refused to talk about entity labels in #38 of this issue ;)
However, time goes by, and now that there's some actual code behind the effort in #1361228: Make the user entity a classed object, I do wonder whether this change is still necessary and/or whether we're going to unnecessarily break other patches/changes down the line by committing it. As this only applies to D8, I'd actually be inclined to hold it off on aforementioned patch, and directly or indirectly move to $account->label().
Comment #53
xjmIn the entity conversion issues we've seen so far, we are retaining various functions as procedural wrappers for entity methods. So I think it's entirely reasonable, perhaps better, to commit this now. At most the user entity patch would need to reroll one or two hunks, I think? And that issue is still NW.
Comment #54
catchI've gone ahead and committed this, it's likely only minor conflicts at most with the entity conversion patch, and it's a better target for completely removing the function if we end up doing that if it's properly owned by user module.
This will need a change notification.
Comment #55
RobLoachThanks!... And agreed.
Comment #56
aspilicious CreditAttribution: aspilicious commentedComment #57
tstoecklerAdded a change notification: http://drupal.org/node/1408514
Could maybe have a look-over before being marked fixed.
Comment #58
xjmLooks good to me, thanks @tstoeckler! I polished the formatting a little and snuck in a semicolon. :)