Problem/Motivation
If you edit the Menu link title to anything else (e.g. "Fish!") it will display correctly/consistently on the Menu links page and across the site. Any title appears to be fine in fact, except "User account"; i.e. if you edit the link title back to "User account" it will show up as "My account" instead again.
Steps to reproduce:
- Fresh install Drupal
- Log in and note the link in the top right titled 'My account'
- Now navigate to the 'User account' menu admin page (admin/structure/menu/manage/account/edit) and note the item titled 'My account'
- Click edit next to 'My account' and see that the menu link title field is actually set to be 'User account'
- Change the menu link title to anything other than "User account" (e.g "Fish!") and click save.
- The item that was 'My account' now displays as the title you just set and on the homepage, 'My account' has been replaced with the new title.
The reason this only happens when the link title is set to "User account" can be seen in the _menu_item_localize() function located in core/includes/menu.inc:641:
if (!$link_translate || ($item['title'] == $item['link_title'])) {
This statement checks to see if the menu link title (the one customized by the user), is the same as the menu title (set by hook_menu() in user.module). In this case the menu title and the menu link title are the same, so this function then processes the title callback.
The 'title callback' is set in the hook_menu() implementation in user.module for the 'user' item. This callback is defined as user_menu_title() and is the ultimate culprit as it returns 'My account' as the title for both authenticated and anonymous users:
function user_menu_title() {
if (!user_is_logged_in()) {
switch (current_path()) {
case 'user' :
case 'user/login' :
return t('Log in');
case 'user/register' :
return t('Create new account');
case 'user/password' :
return t('Request new password');
default :
return t('User account');
}
}
else {
return t('My account');
}
}
_menu_item_localize() tries to pass in the menu link title, as set by the user, as an argument to this callback. However, as user_menu_title() is currently defined, it does not accept any parameters and this argument is ignored.
Proposed resolution
Change the definition of user_menu_title() to accept a single parameter and then return that value.
Note that the patch in #1251188: Set unique titles for user/register, user/password, and user/login menu items improved the logic of this callback to address another issue, but this bug existed prior to that patch.
Remaining tasks
There are also several tests that assume 'My account' - these should be fixed.
Other areas of core that assume 'My account':
core/modules/contact/contact.module (line 22)
core/modules/language/language.module (line 22)
core/modules/openid/openid.module (lines 796, 799)
core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php (lines 159, 200)
core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php (line 425)
core/modules/system/lib/Drupal/system/Tests/Upgrade/FilledStandardUpgradePathTest.php (line 52)
core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php (multiple lines)
User interface changes
Both before and after the patch - "User account" (/user) menu item edit form:
Before patch - frontpage:
Before patch - User account menu admin page:
After patch - frontpage:
After patch - User account menu admin page:
Original report by one_orange_cat
Fresh Drupal install. Login and go to front page - you will see "My account" link.
Go to admin/structure/menu/manage/user-menu and you will see a Menu Link:
My account (disabled)
[Incorrect disabled display issue is raised elsewhere in http://drupal.org/node/1197622]
Now edit this link and you will see (in admin/structure/menu/item/2/edit):
Menu link title: User account
Path: User account
If you edit the Menu link title to anything else (e.g. "Fish!") it will display correctly/consistently on the Menu links page and across the site. Any title appears to be fine in fact, except "User account"; i.e. if you edit the link title back to "User account" it will show up as "My account" instead again.
Thinking this could be connected to various issues floating around in connection with the "My account" entity, perhaps including:
#1251188 Fix page title for user/register, user/password, user/login pages, currently all the same
There is also a helpful dump of the user-menu table in the following issue, showing that "User account" is set as the link_title, even though we see "My account" on screen and elsewhere:
#1337546 Cannot reorder 'User Menu' items for user/register user/login as these are not accessible by admin
Comment | File | Size | Author |
---|---|---|---|
#18 | account-menu-links-1634916-test-only-18.patch | 7.51 KB | dags |
#18 | account-menu-links-1634916-18.patch | 8.61 KB | dags |
#18 | interdiff.txt | 1.85 KB | dags |
#14 | before-and-after-patch.png | 22.7 KB | dags |
#14 | before-patch-homepage.png | 7.98 KB | dags |
Comments
Comment #1
ZenDoodles CreditAttribution: ZenDoodles commentedWe fix issues in the dev version first and backport. Can someone confirm if this is an issue in 8.x?
Comment #2
luke_banana CreditAttribution: luke_banana commentedHey, first comment ever: I've tested this in Drupal 8 and the problem appears there, too. I tried to change the menu link title to words like "Fishes", "Cats" etc. and it worked. When I tried to change it to "User account", it showed up as "My account"...
Sidenote: On "admin/structure/menu/manage/user-menu", the menu link shows up as "My account", if you click on edit, it shows, the menu link title is "User account"... I also didn't have to enable this menu link, it already was.
Comment #3
YesCT CreditAttribution: YesCT commentedtagging novice to make the links use consistant name
Comment #4
dags CreditAttribution: dags commentedFor anyone looking for a quick fix, here's a patch. Aside from fixing the bug, this also changes and removes a couple of tests that were explicitly checking for 'My account' text. This is just a quick fix though, I'm still investigating why 'User account' triggers a different callback from anything else.
Comment #5
dags CreditAttribution: dags commentedComment #7
dudycz CreditAttribution: dudycz commentedI would use:
$link_title = db_query("SELECT link_title from menu_links where link_path='user'")->fetchField();
and then:
':text' => $link_title,
Comment #8
dags CreditAttribution: dags commentedThanks for the suggestion dudycz, that's a much better way to do it. Except that ':text' will cause it to run through drupal_placeholder(), wrapping it in an em tag. Let's use '@text' instead to ensure the text is HTML escaped.
I did some more digging and found that user_menu_title() is ultimately called by _menu_item_localize(), which tries to pass the title as an argument. We can just tell user_menu_title() to take an argument called $link_title and we don't have to query the DB at all. Also, there's no need for the
else
, so let's remove it and just return the translated title.This patch addresses those issues and also fixes some more tests that were explicitly looking for 'My account.' I also found these places in core that make reference to 'My account.'
core/modules/contact/contact.module:22
core/modules/language/language.module:22
core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php:159
core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php:200
core/modules/openid/openid.module:796
core/modules/openid/openid.module:799
Comment #10
YesCT CreditAttribution: YesCT commentedthis could use an issue summary update to clarify the solution. tagging.
Comment #11
dags CreditAttribution: dags commented@YesCT, I updated the issue summary. I haven't done too many issue summaries before. I'd appreciate some feedback to know that I'm doing them correctly.
Also, I'm working on a new patch to address the failing test in #8.
Comment #12
dags CreditAttribution: dags commentedFixes the failing test in #8 where the SearchConfigSettingsFormTest was checking that the text 'User' was not anywhere on the /search page.
Comment #13
YesCT CreditAttribution: YesCT commented@dags the motivation and proposed solution sections are an improvement. The list of the tests to fix in the remaining tasks section is helpful.
I think a simple steps to reproduce section could be added. (using what was originally in the issue as a starting point). use an ordered list for that, and start with "install".
I'm still a bit confused... this patch is fixing the fact that the link can be changed to Fish, or anything, except for User Account?
So after this patch, the link can be set to be User Account?
The issue summary needs a api changes and user interface changes section.
This issue has both I think.
the UI changes section is a good place to put screenshots of before the patch (with User Account showing as My Account) and after the patch (with User Account showing as User Account).
Comment #13.0
dags CreditAttribution: dags commentedrevise summary
Comment #14
dags CreditAttribution: dags commentedWoops.. was trying to update the summary and accidentally posted it in a comment.. thus why these images are attached here.
Comment #14.0
dags CreditAttribution: dags commentedadd before after screens, steps to reproduce, more info about bug.
Comment #15
YesCT CreditAttribution: YesCT commentedI read through the patch, it looks ok standards-wise.
The testbot is green.
The issue summary explanations and screenshots help clarify it.
rtbc.
Comment #16
xjm#12: account-menu-links-1634916-13.patch queued for re-testing.
Comment #17
xjmLet's add a test case that explicitly tests both the default and non-default values for the link text (i.e. test the default value, update it through a
drupalPost()
, and test the new value).Comment #18
dags CreditAttribution: dags commentedHere are some tests. I kinda get the feeling that I should clean up the the naming and phrasing of variables and messages.. let me know if anyone else gets that feeling too.
Comment #20
dags CreditAttribution: dags commentedLooks like the tests aren't actually failing - just throwing couple of PHP notices because of a core bug that's been hanging around for a while. See these issues:
#876580: drupal_valid_path fails for dynamic paths (e.g. user/% cannot be added to menus)
#190867: Remove access check for anonymous users when creating aliases
Comment #21
YesCT CreditAttribution: YesCT commented@dags
The tests-only patch is failing really, right?
And the related issues are related to the purpose of this issue, not the "core bug that's been hanging around for a while", right?
Are the exceptions on the patch:
similar to what I was seeing:
Undefined index: name
in: #1498674-185: Refactor node properties to multilingual?
Is there an issue for that? Or a workaround, so we can get the bot to show the patch as green? Maybe we just submit for a retest?
Comment #22
dags CreditAttribution: dags commented@YesCT I think we need #876580: drupal_valid_path fails for dynamic paths (e.g. user/% cannot be added to menus)
to get into be fixed before these tests will pass. I imagine this will need a reroll too.Comment #22.0
dags CreditAttribution: dags commentedadjust spacing
Comment #23
heddnLet's allow others to work on this.
Comment #32
quietone CreditAttribution: quietone as a volunteer commentedTested on Drupal 9.3.x, standard install and was not able to reproduce the problem. The title is always 'My account'. Plus there was change in #2301313: MenuLinkNG part3 (no conversions): MenuLinkContent UI to display a message that the title and path of the link cannot be edited.
Still applies to Drupal 7.80, changing version.