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.
user_entity_info()
defines format_username($account)
as the 'label callback'
of the User entity. Unfortunately, a label callback expects $entity_type, $entity
as parameters, not just the entity.
Major, as it breaks every code out there that tries to work with entities in a generic way.
Comment | File | Size | Author |
---|---|---|---|
#35 | 1261918-35-label_callback-user.patch | 3.31 KB | mgifford |
#33 | user_entity_tests-1261918-33.patch | 1.54 KB | oriol_e9g |
#28 | 1261918-label_callback-user_3_0.patch | 2.45 KB | catch |
#26 | 1261918-label_callback-user_3.patch | 2.45 KB | dawehner |
#22 | 1261918-label_callback-user.patch | 2.51 KB | dawehner |
Comments
Comment #1
dawehnerIt's kind of obvious that you shouldn't change format_username as this would break a lot of things and it doesn't really make sense to have entity_type in a very specific user function.
Let's see whether the tests are running.
Comment #2
aspilicious CreditAttribution: aspilicious commentedNeeds newline
Code looks ok but could you attach a test only file.
Thnx!
EDIT: Ok I missed the TODO in the tests
4 days to next Drupal core point release.
Comment #3
dawehnerHere is the test patch
Comment #4
dawehnerAnd here comes the total patch.
Comment #5
yoroy CreditAttribution: yoroy commentedSo will this make things show up in the UI that were previously hidden? If so, a screenshot would be much appreciated.
Comment #7
tstoecklerInteresting, never seen that. Is there a difference between that and
drupal_anonymous_user()
?This should be
$this->anonymous
and not$this->account
. That's test fail #1. This shows that the assertion works, which is good. :)In general, I can't believe we/I missed this in #1096446: entity_label() is not passing along the $entity_type parameter, when looking for label callbacks I only searched for "label" on api.drupal.org, *slapsforehead*...
Comment #8
dawehnerThere is a huge difference internally, because user_load does provide a full user object while drupal_anonymous_user has just a small version of it. Let's use drupal_anonymous_user, as this will be probably used on real sites.
About the test failures, *facepalm*. When i made this, the tests runned locally not as well, but i thought that's a problem of my setup.
Okay here is a new one.
Comment #10
Bojhan CreditAttribution: Bojhan commentedWonder if yoroy's question still stands.
Comment #11
dawehnerAbout yoroy's question. Core doesn't use entity_label yet somewhere at all, so nothing changes for the user.
It's basically just an api which could be used on other modules.
Comment #12
Bojhan CreditAttribution: Bojhan commentedOke, just needs someone to fix the test.
Comment #13
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis actually only applies to Drupal 8. Not sure how I managed to bump into in on Drupal 7... probably messed up with my development environment somehow.
Comment #14
catch*d8 suffixed patches are ignored by the bot, and this patch has never passed yet, so can't be RTBC.
Comment #15
Bojhan CreditAttribution: Bojhan commentedComment #16
Bojhan CreditAttribution: Bojhan commentedComment #17
dawehnerThis is probably an old patch, as checking for the name of the anonymous user but giving the registered account can't work :) Blame me. This was already fixed in #8 but is not part of #13
Comment #18
tstoecklerHere's a new one. I actually edited the patch file, so things might blow up.
I fixed the test and also went back to using assertEqual() directly.
Comment #20
tstoecklerOkay that was the D7 patch, in D8 the argument order is reversed.
This one should work.
Comment #21
tstoecklerAnd that should of course be reversed as well.
It should be URI callback, right?
See above.
See above.
Comment #22
dawehnerOh thanks true.
Okay here is the patch for d8, let's get this ready first before continue to work on the d7 version.
Comment #23
tstoecklerI don't think we need a D7 patch here.
In D7 $entity is passed as first argument so format_username() is fine as 'label callback'.
Comment #24
dawehnerAh okay make sense, thanks.
In general the tests should be backported.
Comment #25
Dave ReidWith regards to the @todo in the test, user_uri() doesn't care if the user is anonymous or not. Either way it should return a value of 'user/0'.
Comment #26
dawehnerLet's remove the todo
Comment #27
catchThis looks good but there is a minor whitespace issue:
Comment #28
catchFixed the whitespace myself. I'm marking this RTBC. If there's no objections before Friday I'll commit it then.
Comment #29
tstoecklerRTBC++
Go for it! :)
Comment #30
chx CreditAttribution: chx commentedLooks good.
Comment #31
catchThanks, two extras is plenty, so committed and pushed to 8.x.
Discussion here suggests there's no Drupal 7 bug here, but maybe we can backport the tests?
Comment #32
RobLoachRelated: #1227942: Rename format_username() now that it's in user.module
Comment #33
oriol_e9gTests backported and passed locally :D
Comment #34
mgifford33: user_entity_tests-1261918-33.patch queued for re-testing.
Comment #35
mgiffordThe patch in #33 only adds tests to modules/user/user.test
Doesn't actually fix the problem.