Steps to reproduce
- Installed current Drupal checkout
- Created new user "foo"
- Went to user/2
--> Breadcrumb is "Home » root", with "root" being linked to user/1 – should be just "Home".
--> Title is (correctly) "foo".
- Went to user/2/edit
--> Same breadcrumb as above – should (probably) be "Home » foo".
--> Title is "root" – should be "foo".
At least the last line is very clearly not by design, the breadcrumb is also very confusing. (The displayed main content is correct in all cases.)
In another install I also had the problem that sub-tasks of a user/%/foo local task would display an additional (third) breadcrumb, "Foo", linked to "user/1/foo/bar", but I couldn't reproduce that one easily. However, I imagine it would be fixed with this.
This is probably a follow-up to #907690: Breadcrumbs don't work for dynamic paths & local tasks #2, but after over 350 comments, I think it deserves to rest.
Also, I'm not sure about the priority, but I guess displaying completely wrong titles and confusing breadcrumbs even for normal users is pretty critical.
Comment | File | Size | Author |
---|---|---|---|
#126 | drupal.user-account.125.patch | 3.94 KB | sun |
#124 | drupal.user-account.124.patch | 4.22 KB | manarth |
#120 | drupal.user-account.120.patch | 3.29 KB | manarth |
#116 | drupal.user-account.116.patch | 3.72 KB | manarth |
#114 | drupal.user-account.114.patch | 3.72 KB | manarth |
Comments
Comment #1
sunThis is actually extensively covered by unit tests, so I'm not sure what went wrong for you. Definitely not critical.
Comment #2
drunken monkeyOh, sorry for that. I especially triple-checked, because I couldn't believe this would have been overlooked, but it always happened (right now too, again with complete fresh D7 checkout and database). So you also couldn't reproduce it locally?
Very weird …
Comment #3
sun"root" can technically only appear if there is a menu link in {menu_links} with the link_title "root". Can you figure out whether there is one and from where it comes?
Comment #4
drunken monkeyNo, there's none. But normally, the ones linking to a user page are created with a title callback like
user_page_title()
, aren't they?Sorry, I don't know enough about the menu system to make any helpful guesses here … I can just say that it's definitely broken for me. But if there are other things I could check that you can think of (maybe some function calls I could track?), please tell me.
Comment #5
webchickI think I see the misunderstanding. Drunken monkey's user 1 is called "root".
My user 1 is "admin", and these are the title and breadcrumbs at user/2/shortcuts:
I assume this is probably actually an issue with user.module somewhere.
This probably isn't a release blocker, but it's pretty nasty...
Comment #6
webchickAnd we clearly either need new tests or to fix the old ones.
Comment #7
webchickLet's try that as a title.
Comment #8
drunken monkeyOh, sorry – yeah, user 1 is "root" here, should have made that clear right away …
And thanks a bunch for the confirmation. Good to hear I'm not just insane. ;)
Shipping with wrong menus for the user module would btw sound critical to me, but won't argue there.
Comment #9
markabur CreditAttribution: markabur commentedI'm pretty sure this is due to the some of the changes in menu.inc from #907690: Breadcrumbs don't work for dynamic paths & local tasks #2.
Comment #10
klonos...subscribing
Comment #11
pwolanin CreditAttribution: pwolanin commentedseems like we had to fix this once for D6 - %user_category maybe?
Comment #12
webchickMmm. Reflecting on it more, unfortunately, this is actually critical.
Comment #13
mradcliffeI wrote a quick test that created two users, one with admin rights, logged in with the admin user, viewed the other's view and edit page. It passed the correct breadcrumb and title assertions.
It looks like this might only be a problem with user 1 as those two users were uid 2 and 3 respectively.
Comment #14
markabur CreditAttribution: markabur commentedI can reproduce this with user 2 and user 3 like so:
- Create 2 non-admin users
- Give View user profiles permission to Authenticated User
- Log in as User 2
- Go to
user/3
Result is that the title is ok but the breadcrumb still shows user 2 (the currently logged in user).
Comment #15
mradcliffeNevermind. CVS didn't clean up properly, and I didn't have a clean checkout. Sorry.
Here's a patch for my test I wrote. It now fails like it should ;-)
Comment #17
bjaspan CreditAttribution: bjaspan commentedSo, ummm.... Drupal 7 is useless until this is fixed?
Comment #18
klonos...not useless. I'd say rather crippled. That's why this is critical ;)
Comment #19
klonosThis bug is that user n's breadcrumb is shown as
Home >> [n-1 username]
instead ofHome >> [n username]
the way I see it. Right? Does this happen for all users or did you people only test it with 3 users? If so, could this simply be a matter of incrementing some variable starting from 1 instead of 0 or something like that? I actually wouldn't know. I am just guessing here.Comment #20
klonos...I meant to also ask: does the
[n-1 username]
part of the breadcrumb link to the right user though or is the link messed too?Comment #21
justafishThe breadcrumb is showing the currently logged in user for me, no matter which user I go to. I created a few accounts to test this with.
The link is pointing to the currently logged in user also.
Comment #22
justafishThe issue is that the $uid passed to user_page_title is wrong
Comment #23
justafishSo it seems that it's being overridden by the user_uid_only_optional() function, which is used in the argument for the parent menu item, which sets the argument to that of the currently logged in user. You can see this by changing $items['user/%user_uid_only_optional'] in user_menu to $items['user/%'] and the title and breadcrumb on the edit / shortcuts / etc pages works as expected. I'm not currently sure why this is behaving this way...
Comment #24
markabur CreditAttribution: markabur commentedI've done some digging and narrowed it down to the changes in menu_set_active_trail() in #907690: Breadcrumbs don't work for dynamic paths & local tasks #2. Part of the problem seems to be that menu_link_get_preferred() isn't working as expected in this situation. E.g. on the edit screen it is returning
user/%/edit
as the "preferred" link, when it should be returninguser/2/edit
.Commenting-out the line following step 3 in menu.inc affects this bug but doesn't fix it completely (it fixes the title but makes the breadcrumb weirder):
Comment #25
justafishShould it? The mapping returned by menu_link_get_preferred() seems correct. Also, if you look at the same situation for nodes then the link path and router paths returned are node/%/edit not node/12/edit, but the breadcrumbs are still right.
(not my area (yet ;) ), so apologies if I'm talking rubbish!)
Comment #26
sunPlease add those assertions to the existing MenuBreadcrumbsTestCase in modules/simpletest/tests/menu.test instead.
- Insert them as the first assertions after the initial variable setup.
- Use the same assertion method like all the rest of that test case.
- Make sure that the assertions come before the existing assertions.
- You may copy the required assertion lines from further down in the existing test case, but do not alter any of the existing test code.
Powered by Dreditor.
Comment #27
mradcliffeI think this is part of a larger issue. There are breadcrumb and title tests in other module's tests. I followed node.test.
Maybe we need an issue to move all of those into menu.test?
Or should we split the title and breadcrumb assertions into different tests?
Comment #28
justafishok this is how I understand the issue to be at the moment (sorry for my limited knowledge in this area):
- The incorrect breadcrumb and title are rendered using the parent item's title
- The parent item's title is generated from:
Which generates that title with the following:
- So therefore a value of '%' is being passed to the parent menu item instead of the desired uid
Comment #29
moshe weitzman CreditAttribution: moshe weitzman commentedSo, ummm.... Drupal 7 is useless until this is fixed?
That’s Barry's subtle way of disagreeing with the Critical priority here. And I agree. I would call this a Normal bug. Not in the mood to change it over Webchick though.
Comment #30
webchickLet's split the difference at "major". But I don't think we can ship with this broken, personally.
Comment #31
mradcliffeI agree with not shipping this with it broken. It would really undermine Drupal credibility to have a bug this obvious in release. Tagging "Release blocker" (it has some 7.x tasks and 1 8.x task?).
Comment #32
sun@justafish's analysis looks correct to me. The problem is %user_uid_only_optional, which happens to load the wrong user account for the case
$arg == '%'
.Next steps:
1) Re-implement the tests in the way I stated above.
2) Remove that
$arg == '%'
from the %user_uid_only_optional argument loader and see what else breaks. The breadcrumb tests at least should pass with that.Comment #33
sunoops. Stale browser tab.
Comment #34
klonosAha! That was irony. Sorry I didn't realize that ;)
Comment #35
klonos...stale tab too. Sorry.
Comment #36
chx CreditAttribution: chx commentedComment #37
mradcliffeOkay, here are the user breadcrumb tests using assertBreadcrumb in MenuBreadcrumbTestCase. Several changes:
#3 might be too wild and crazy of an idea. I like cutting down the redundancy a bit though.
Edit: once again, this should fail in 6 places currently.
Comment #39
manarth CreditAttribution: manarth commentedmenu_get_item and menu_link_get_preferred are returning values with the URL arguments in the data-set. These functions look correct.
When the menu system processes menu_tree_page_data, the URL arguments aren't passed as parameters to menu_build_tree.
Probably, either menu_build_tree or menu_tree_page_data will need to change, but I'm not sure exactly what's required right now. I'll come back to this tomorrow - please post advice/solutions/patches in the meantime :-)
Comment #40
chx CreditAttribution: chx commentedI can't reproduce the title bug while the breadcrumb is equally broken on Drupal 6. If you can reproduce the title issue please screenshot. Edit: nk is uid 1, chx is uid 2. Drupal 6 says "my account" , Drupal 7 says "nk" in the breadcrumb. It's the same link however.
Comment #41
chx CreditAttribution: chx commentedAnd unless someone can reproduce the title bug, this is not a release blocker: anything that did not block Drupal 6 (see "my account" in the breadcrumb? you can try on drupal.org too!) should not block Drupal 7.
Comment #42
chx CreditAttribution: chx commentedUm, sorry, it's only user/2/edit that has a broken title? That's the issue. We do not fix the breadcrumb, that's a different issue.
Comment #43
chx CreditAttribution: chx commentedFall back to Drupal 6. This is hopeless.
Comment #45
markabur CreditAttribution: markabur commentedWell, user/2/shortcuts too (see @webchick's screenshot). I've looked at user/2/track and user/2/contact and they are fine however.
Comment #46
chx CreditAttribution: chx commentedThis patch gets us out of Dodge.
Comment #47
chx CreditAttribution: chx commentedSure! we can do shortcuts too. Note to anyone trying to fix the breadcrumb: the my account (d6) / username (d7) link is the same as the one that gets into the breadcrumb. The very scaffolding to separate them is missing. A breadcrumb_alter might be a hackish fix in another issue if you want. Proper fix is unavailable AFAIK. As the title comes from the same place, proper fix is also unavailable.
Comment #48
chx CreditAttribution: chx commentedTest is already included.
Comment #49
markabur CreditAttribution: markabur commentedGreat, #47 fixes the title on the edit and shortcuts screens. A stray backslash snuck in here:
Comment #50
chx CreditAttribution: chx commentedHm, I thought I ran my tests and they passed. It's very curious -- the command line runner passes UserEditTestCase, the user interface runner ends with an error before the batch but the error screen just shows passes. The bot have found a number of seemingly unrelated issues failing. Needs a followup issue! The things you find with a typo.
Comment #52
mradcliffeIt failed because MenuBreadcrumbTestCase is still expecting the breadcrumb to be the newer way.
Was this new way to display user page title (and breadcrumb is a separate issue now?) a part of UX design changes? If not, then I guess this rollback to D6 behavior is fine.
Comment #53
chx CreditAttribution: chx commentedThis now passes.
Comment #54
sun@mradcliffe: Can you re-roll #37 and just do what I stated in #26 and #32? This patch should not touch any of the other breadcrumb assertions.
I'm not sure what chx is trying to achieve by derailing this issue first by not reading the issue and afterwards with those patches.
Comment #55
sunIt's always the same mess. Attached patch implements the test procedure and is therefore expected to fail. Reproduce first, then fix. Anything else does not make sense.
Comment #57
sunI'm sorry, but there is no possible way to make this remotely work, because:
We have gazillions of different expectations for the current mess of user path and user/% path links:
user
itself should not show up in any menu, only in the breadcrumb for user register, password, and login pages.user/%
should show up on all pages in the user menu, containing the title "My account" or the current user's name.Note that the link in the user menu is the untranslated router item; i.e.
user/%
itself. We expect % to be translated into the current user's uid, but only for this link.user/%
should appear in the breadcrumb when visitinguser/123/edit
, whereas % should be naturally and logically translated with 123, not the current user's uid. This entirely contradicts the last bullet.user/logout
should appear in the user menu, next touser/%
, but none of the other sibling paths should appear (such asuser/register
oruser/password
, and whatnot).user/%
appears in any menu, and therefore, this entire problem space is limited to our other weird expectations of how this untranslated link should appear (on [any] pages that are not even related to the user account page).We have to
user/me
is required.Comment #58
chx CreditAttribution: chx commentedWould it be possible to avoid
if (is_object($uid))
?Comment #59
sunNot sure what has been left unclear. It would really help if you would carefully read issue follow-ups.
Comment #61
chx CreditAttribution: chx commentedAnd it would tremendously help if you would stop a) calling me out which I have despite your claims otherwise I never did. I have talked to you extremely patiently for extreme long time b) throwing around generic claims. How am I supposed to know that this is such a thing you vaguely hinted at? I can't even count how many times I asked you to speak in specifics, concrete examples.
Comment #62
sunSomething along the lines of attached patch. I'll explain the remaining problem in pictures, as I seem to speak Spanish.
Comment #63
chx CreditAttribution: chx commentedWhat I have "tried to achive" is fixing the edit / shortcut page title . I have my doubts as I have expressed above about our abilities to prepare a proper patch for D7. As far as I understand the breadcrumb contains a copy of the menu link pointing to my account therefore it will always be broken unless you change where the breadcrumb comes from. So I have thought it is impossible to fix the breadcrumb in Drupal 7 and have rolled back the page title to Drupal 6. Could you please explain me where I am wrong? Does the breadcrumb not contain a copy of the "my account" link? If it does (and your screenshots indicate that), then what does ripping out existing performance optimizations buy us versus the posted , passing , ugly rollback?
Comment #65
manarth CreditAttribution: manarth commentedThe patch in #62 has a few issues:
- php notice:
- 2 instances of "My account" appear in the top-right menu.
- the second of the "My account" links in the top-right link to "user/%" which does not work.
The patch in #53 also has issues:
- the <h1> title (on user/xxx) is correct, but the breadcrumb gives the url/text of the current logged-in user, not the user whose account is being viewed.
Comment #66
manarth CreditAttribution: manarth commentedNeither of the patches in #62 and #53 resolve the issue's cause, which is that the API functions (e.g. menu_get_active_trail) return incorrect data, because some of the APIs are not being passed the correct data.
This patch attempts to resolve the issue by applying the current path-context to the APIs, so the correct data is returned, however the root cause is that user/% can have 2 different contexts on the same page: in some places (e.g. breadcrumbs, menu-active-trail) it will be the context of the current URL, in others (e.g. the top-right user menu) it should be without context (and so provide a link to the current logged-in user's account).
This patch can't address that problem.
Issues with this patch:
- on user/xxx the menu text/url in the top-right (secondary-menu) will point to user/xxx instead of the currently-logged-in user.
- patch uses arg(). There may be a better-performing alternative.
Comment #67
sunSolved it. Breadcrumb tests pass. Didn't look at the other test failures.
Comment #68
sunAlthough I believe it is wrong, restored %user_uid_optional argument loader and to_arg function for Blog, Tracker, and other modules.
Comment #69
manarth CreditAttribution: manarth commentedWorth waiting for the testbot results, but manual testing of sun's patches in #67 and #68 both apply and appear to work.
My manual tests are:
> in an environment with 2 users (uid1 and a new test user uid 14 with username "test_user_foo")
> browse to user/1: check: top-right "My account" link has correct text and href, and that breadcrumb shows "Home"
> browse to user/1/edit: check: top-right "My account" link has correct text and href, and that breadcrumb shows "Home >> admin"
> browse to user/14: check: top-right "My account" link has correct text and href, and that breadcrumb shows "Home"
> browse to user/14/edit: check: top-right "My account" has correct text and href, and that breadcrumb shows "Home >> test_user_foo"
> browse to node/1: check: top-right "My account" has correct text and href, and that breadcrumb shows "Home"
> browse to node/1/edit: check: top-right "My account" has correct text and href, and that breadcrumb shows "Home >> test node" (where "test node" is the node title)
I've no preference between #67 and #68: they both appear to work (from the manual tests: lets see what testbot says tho!)
Comment #71
pwolanin CreditAttribution: pwolanin commentedIn Drupal 6, the breeadcrumb says "Home › My account" when I am an admin or a normal user viewing another user's account - thus, fixing that aspect is NOT part of the critical bug. It has a breadcrumb in Drupal 6 of "Home › My account › XXX" When I am user 1, editing the account of user XXX, so even that would not be a regression.
Comment #72
markabur CreditAttribution: markabur commentedTried #68 and it fixes the title and breadcrumbs to what I would expect as a new Drupal user (i.e. not someone used to the d6 way of doing it). So it fixes the regression and improves Drupal's usability as well.
Comment #73
pwolanin CreditAttribution: pwolanin commentedSince when does this work?
If it does work it's only by accident and should not be used in core.
Comment #74
sunI've tried to figure out what is going wrong in those OpenID tests, but was not able to identify the cause. They also fail for me locally. For some unknown reason, the hashed password in the user password reset URL is different to the expected hash that is re-generated and tested against in the user/reset page callback. However, that must be something entirely different, unrelated to the user menu changes, because the page callback gets the $hashed_pass argument -- it's just not the correct value, and only in those OpenID tests (for any reason).
Apparently, all other user registration tests are passing, so I'm really not sure what's going on there. I recognized that the OpenID tests are rebuilding the password reset URL, instead of parsing and reading out the URL from the sent out e-mail.
re: #71: If it was wrong in D6 already, then you are basically right in that we don't have to fix the duplicate breadcrumb links to user and user/# in the breadcrumb. However, as I tried to explain in #57, we have to remove the weird logic that tries to output the untranslated user/% link anyway, which is what the latest patch already achieves by restoring D6's "My account" link pointing to "user" instead of "user/%". Only putting "user" in the user menu, forcing "user/%" to stay in the default navigation menu (and which therefore also eliminates the need for any performance optimization for the "user/%" path, which was only done, because the user menu containing the user/% link was output on all pages).
re: #73: We are facing the problem that the user menu should contain a link to "user" (My account) and "user/logout" (Logout). I agree that manually setting 'plid' on user/logout is a crappy hack, but as of now, I don't see any other way to disable the menu system's automated menu link parenting logic. This problem is new to D7, because we changed the "logout" path to "user/logout". In D6, the paths "user" and "logout" were able to happily live next to each other in the menu, because "logout" was not registered below "user". We only have this issue in D7, since both links should appear in the same menu, but still next to each other. After all, forcing 'plid' to 0 only affects and disables the automated router item parenting logic in menu_link_save(), when the corresponding menu link has not been customized.
In the end, I don't see a more correct solution than the current patch. What remains is to get the tests passing.
Comment #75
sunResolved/reverted another change in expectations: Anonymous users should see "User account" as link title, not "My account", in case the link to "user" is output.
Also clarified comments.
Comment #76
sunRemoved a needlessly duplicated comment in the added test assertions.
Comment #78
pwolanin CreditAttribution: pwolanin commentedLet's move /logout back to the top level. Why does it need to be under /user?
Comment #79
sunFixed those OpenID tests. This one should pass.
Comment #81
pwolanin CreditAttribution: pwolanin commentedThis should not be committed with the plid hack.
We need to either change the path back to just /logout, or user module needs to implement hook_menu_link_alter() to provide the desired fix-up.
Comment #82
sunTrying again. Forgot that testbot runs without clean URLs.
Comment #84
sunHm! Closer inspection of the remaining test failure makes me believe we're facing the last remaining bit of #550254: Menu links are sometimes not properly re-parented again.
So let's simply try whether merging that patch makes the upgrade tests pass.
Comment #86
sunAlright. Let's try hook_menu_link_alter() then.
Comment #88
sunI don't really get what's happening in that upgrade path. One last try.
Comment #89
sunSo is everyone happy now?
I've read and tried to understand the update queries that are performed in system_update_7015(), but I have no clue why they have been done in this way, and why the "Log out" link worked (?) previously... I didn't verify, but I suspect that the (non-customized) link was not moved to the user menu upon upgrade previously, so tests merely passed, because the link still appeared in the Navigation menu. At least, that's my bet.
Powered by Dreditor.
Comment #90
markabur CreditAttribution: markabur commentedStill works from a front-end clicking-around point of view, good work!
Comment #91
sun#88: drupal.user-breadcrumb.88.patch queued for re-testing.
Comment #92
sunI'd actually prefer the 'plid' definition in hook_menu(), as it keeps the special definition close to the router item definition (the user_menu_link_alter() implementation is many code lines away), and effectively leads to the same result. But anyway, I'm happy either way.
Comment #93
chx CreditAttribution: chx commentedwow what a trick! congratulations! I never though it even possible to fix this issue but moving the link
aroundinto another menu... brilliant. just sheer genius.Both pwolanin and I seem not to like that 'plid' trick, the current approach is so much better.
Comment #94
catch+ * Parses the last sent e-mail and returns the one-time login link URL.
Core uses email.
No comma after 'i.e.'.
So does this revert back to loading the full user everywhere? Did anyone check?
Comment #95
sunNo, not that I know of. I used e-mail everywhere, and I used it a lot.
No wonder I still see so many instances, even after correcting many. Some of the largest grammar style guides precisely state that there should be a comma after "i.e." and "e.g.". Since most of them are printed books, I can only reference to insightful online style guides like http://www.grammarbook.com/punctuation/commas.asp
As in D6, the user/% path arguments are only loaded when actually requested. The link to "My account" that appears on all pages no longer links to user/%, but the static /user path, which doesn't load anything.
Comment #96
catchi.e., vs. i.e. is American English, :(
e-mail, sorry bad grep.
user/% I'm going to verify either way a bit later.
Comment #97
catchDouble checked user_load() and it's OK. One day I will post the British English translation for Drupal core.
Comment #98
webchickOk, it seems the latest patch meets the menu maintainers' requirements, and has been tested to work successfully. Comes with tests to prove it, too.
Committed to HEAD. Thanks a lot, all!
Comment #99
BerdirAs a note, the patch did remove the function "user_uid_only_optional_to_arg".
I accidently used that instead of %user_uid_optional in userpoints D7 port (Patch to change that already exists and not because of this issue...) and this leads to a FATAL error with the current HEAD of userpoints.module.
Sounds like an API change to me, maybe someone else was using it already? :)
Comment #100
David_Rothstein CreditAttribution: David_Rothstein commented1. This patch seems to have caused #937916: Anonymous users see a "User account" link on the front page of a new site.
2. It also seems to have introduced a design change that wasn't really discussed explicitly above. See the attached screenshots. Whereas the user menu on the top right used to have a link with the current logged-in user's name ("David" in the case of the screenshot), it now goes back to the D6 way of saying "My account".
Regardless of whether #2 was intentional or not, it seems to be a large change to have made without any design discussion. Should we reopen this for that?
Comment #101
David_Rothstein CreditAttribution: David_Rothstein commentedAdding a tag.
Comment #102
aspilicious CreditAttribution: aspilicious commentedYes we have to reopen this...
Comment #103
manarth CreditAttribution: manarth commentedIf this needs work, it also needs a new test.
Comment #104
sunHm.
1) Perfectly possible that I'm completely wrong, but I was under the assumption that anonymous users would see a "User account" link; i.e., as fall back when the user login block is not enabled? (At least, didn't this exist in D6?) If I'm wrong here, then it's merely a matter of replacing the 'access callback' with 'user_is_logged_in'.
2) Actually, the original design documents contained "My account" as link title, not the user's name. The user's name was only supposed to appear in the Toolbar, but not in the user menu. Since the previous implementation was built off the existing user/% router path, there was no easy way to _not_ display the user's name, as that router path information is used for other purposes. So I recalled that various people were not happy with the user name appearing there, and because this change allowed for "My account", the menu title callback shows that. Like with 1), this can be easily changed by adjusting the title callback to not return "My account", but format_username($GLOBALS['user']).
No performance penalty or technical problems involved for both changes, so I'm leaving decisions to the UX team.
Comment #105
sunThat said, "User account" is the expected page title for the user/login, user/register, and user/password pages, and the title callback is responsible for that. If we decide to hide the link for anonymous users, then we likely need hook_menu_link_translated_alter(), so we always allow access to the router item (like now), which normally always shows the menu link, but if user_is_anonymous(), then we dynamically set 'access' to FALSE.
Comment #106
manarth CreditAttribution: manarth commentedIf it's worthy of discussion, it's worthy of a test, so that regression bugs are easily recognised.
This patch checks that:
- the secondary-links menu contains a "My account" link pointing to "/user".
- the secondary-links menu contains a "Log out" link pointing to "/user/logout".
Comment #107
chx CreditAttribution: chx commentedIn D6 you definitely did not see a My account link for anonymous. This ingenious fix might need to be rolled back :( and manarth, thanks for the test .
Comment #108
markabur CreditAttribution: markabur commentedThe return of "My account" (for logged-in users) is a good thing. It's an important link that should be easy to find when you're looking for it.
- If the user forgets their username then they are going to have a difficult time getting to their user page where they can see it. :-O
- Having cross-site standards such as "My account" improves the usability of all of them.
- A lengthy username could make the toolbar look odd, which is fine, but I as a designer wouldn't want it messing up the page layout too. "My account" OTOH is a nice predictable bit of text.
Comment #109
sunAttached patch hides the "User account" link for anonymous users.
Comment #110
webchickWhile we're at it, let's please put the user_uid_only_optional_to_arg() function back. I clearly wasn't paying attention when I reviewed this patch, but that's an unnecessary API change. And just because User module doesn't need it doesn't necessarily mean nothing in contrib needs it.
Comment #111
webchickAnd it causes "Fatal error: undefined function user_uid_only_optional_to_arg()." when you update the core files to the latest version. Sad panda.
Comment #112
manarth CreditAttribution: manarth commentedThis patch:
- Adds the tests in #106 (with minor tweaks to support non-clean-urls)
- Adds Sun's patch in #109
- Adds a new assertion for the patch in #109
- Restores the user_uid_only_optional_to_arg function.
Comment #113
sun1) Trailing white-space.
2) The @todo needs to be updated. Actually, the phpDoc description (not summary) should state:
"
Deprecated. Use %user_uid_optional instead.
@todo D8: Remove.
"
1) Comments should form proper sentences; i.e., end with a period.
2) Trailing white-space (also elsewhere in the test).
3) Wrong indentation (also elsewhere in the test).
We can remove the colon and just continue the sentence with:
'for "My account" and "Logout".'
Of course, wrapped at 80 chars.
Powered by Dreditor.
Comment #114
manarth CreditAttribution: manarth commentedUpdated patch to address the issues in #113.
Comment #116
manarth CreditAttribution: manarth commentedFixing broken patch from #114.
Comment #117
manarth CreditAttribution: manarth commentedComment #118
sunThanks for re-rolling, manarth. I think this patch is ready to fly.
Comment #119
webchickHuh. Interesting. Is that the only way to fix this? I'm confused about the layer of indirection here. We're faking that we've just translated a menu link when we haven't. Why don't we just put these lines:
into user_menu_link_alter() directly?
At the very least this needs a butt-load of comments to explain why we're doing something so odd. But I'm not really pro- this approach unless there's an extremely good reason, because this is a complete WTF.
Comment #120
manarth CreditAttribution: manarth commentedI gave that a try, and the tests in the patch fail (the secondary menu isn't removed: anon users see a "User account" link). I presume sun gave that a try, and switched to faking the translation because regular hook_menu_link_alter can't do this.
Definitely open to other ideas. FWIW, I've attached my (failing) patch so others can see if I've missed anything.
Comment #121
sunI did not look up whether there is a new/better way to pass the 'alter' option along to the menu link for router items. The implementation in #116 is the one that is known to work since Drupal 6.
Comment #122
chx CreditAttribution: chx commentedhttp://api.drupal.org/api/function/hook_menu_link_alter Alter the data being saved to the {menu_links} table being saved so i dunno what do you want from that poor hook? But, care to remind me why we can't put that check into the access callback of 'user' ...?
Comment #123
sunWe do not want to limit access to the router item. We only want to hide the link that points to it, in case the current user is anonymous. Therefore, the router item's access callback is no help.
The proposed solution simply leverages hook_translated_menu_link_alter() to conditionally hide the link for anonymous users. Authenticated users are expected to see the link.
AFAIK, putting the information directly into the router item is not officially supported/wanted:
Therefore, the indirection from hook_menu() to hook_menu_link_alter() to hook_translated_menu_link_alter() is required to invoke user_translated_menu_link_alter() for that menu link.
Comment #124
manarth CreditAttribution: manarth commentedThe difficulty is that $item['access'] must be true for all users, but $item['hidden'] must be conditionally set for page-requests from anonymous users.
The menu system provides a callback-hook for access, but only a boolean for hidden, so this must be checked on each page request (it cannot be set in hook_menu or hook_menu_alter because the output from these is built then cached).
I've taken the patch in 116, added comments to try to explain the code, and switched $link['access'] = FALSE; to $link['hidden'] = TRUE; to make it clearer what we're trying to achieve.
(NB: the word 'translated' in hook_translated_menu_link_alter is misleading: nothing to do with language translation. Simply means altered-per-request.)
Comment #125
webchickSadly, I have to add this to the beta blockers list. When you try to update beta1 to HEAD you get:
Fatal error: Call to undefined function user_uid_only_optional_to_arg() in /Users/webchick/Sites/core/includes/menu.inc on line 776
Comment #126
sunShortened + rephrased comments. Also changed 'hidden' from TRUE to 1, as that is the menu system's internally used value.
Comment #127
sun.
Comment #128
catchBreaks beta-beta upgrad path apparently.
Comment #129
catchComment #130
webchickOk, since #126 is essentially the same as #124 with slightly re-worded comments and a TRUE > 1 fix, I'm going to count that as an RTBC. sun's argument for scaling back the comments is that we shouldn't get into that level of API detail within a function body. I agree. However, manarth's description is far better than what's currently at http://api.drupal.org/api/function/hook_translated_menu_link_alter/6 so I'd like to see a follow-up issue to vastly improve the documentation of that hook. Most people will have absolutely no idea it could be used for this purpose.
Committed #126 to HEAD.
Comment #131
bleen CreditAttribution: bleen commentedbunch of crossposts
Comment #132
bleen CreditAttribution: bleen commentedhahaahaha cross posts while fixing crosspost
Comment #133
webchickFollow-ups:
#950276: Improve documentation of hook_translated_menu_link_alter()
#950278: Change hook_translated_menu_link_alter() into hook_menu_link_translated_alter()