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:

  1. Fresh install Drupal
  2. Log in and note the link in the top right titled 'My account'
  3. Now navigate to the 'User account' menu admin page (admin/structure/menu/manage/account/edit) and note the item titled 'My account'
  4. Click edit next to 'My account' and see that the menu link title field is actually set to be 'User account'
  5. Change the menu link title to anything other than "User account" (e.g "Fish!") and click save.
  6. 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-and-after-patch.png

Before patch - frontpage:
before-patch-homepage.png
Before patch - User account menu admin page:
before-patch-menu-admin.png

After patch - frontpage:
after-patch-homepage.png
After patch - User account menu admin page:
after-patch-menu-admin.png

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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ZenDoodles’s picture

Version: 7.14 » 8.x-dev
Issue tags: +Needs backport to D7

We fix issues in the dev version first and backport. Can someone confirm if this is an issue in 8.x?

luke_banana’s picture

Hey, 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.

YesCT’s picture

Issue tags: +Novice

tagging novice to make the links use consistant name

dags’s picture

Issue tags: -Novice
FileSize
2.25 KB

For 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.

dags’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, account-menu-links-1634916-4.patch, failed testing.

dudycz’s picture

Status: Needs work » Needs review

I would use:
$link_title = db_query("SELECT link_title from menu_links where link_path='user'")->fetchField();

and then:
':text' => $link_title,

dags’s picture

Status: Needs work » Needs review
FileSize
5.72 KB
6.45 KB

Thanks 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

Status: Needs review » Needs work

The last submitted patch, account-menu-links-1634916-8.patch, failed testing.

YesCT’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

this could use an issue summary update to clarify the solution. tagging.

dags’s picture

Assigned: Unassigned » dags
Issue tags: -Needs issue summary update

@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.

dags’s picture

Status: Needs work » Needs review
FileSize
796 bytes
7.23 KB

Fixes the failing test in #8 where the SearchConfigSettingsFormTest was checking that the text 'User' was not anywhere on the /search page.

YesCT’s picture

@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).

dags’s picture

Issue summary: View changes

revise summary

dags’s picture

Woops.. was trying to update the summary and accidentally posted it in a comment.. thus why these images are attached here.

dags’s picture

Issue summary: View changes

add before after screens, steps to reproduce, more info about bug.

YesCT’s picture

Status: Needs review » Reviewed & tested by the community

I read through the patch, it looks ok standards-wise.
The testbot is green.
The issue summary explanations and screenshots help clarify it.

rtbc.

xjm’s picture

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Let'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).

dags’s picture

Status: Needs work » Needs review
FileSize
1.85 KB
8.61 KB
7.51 KB

Here 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.

Status: Needs review » Needs work

The last submitted patch, account-menu-links-1634916-18.patch, failed testing.

dags’s picture

Looks 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

YesCT’s picture

@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:

Drupal\user\Tests\UserAccountLinksTests	72	0	2
Message	Group	Filename	Line	Function	Status
Undefined variable: form_item	Notice	path.inc	208	drupal_valid_path()	
Undefined variable: form_item	Notice	path.inc	209	drupal_valid_path()

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?

dags’s picture

Status: Needs work » Needs review

@YesCT I think we need #876580: drupal_valid_path fails for dynamic paths (e.g. user/% cannot be added to menus) to get in to be fixed before these tests will pass. I imagine this will need a reroll too.

dags’s picture

Issue summary: View changes

adjust spacing

heddn’s picture

Assigned: dags » Unassigned
Issue summary: View changes
Status: Needs review » Needs work

Let's allow others to work on this.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.9.x-dev » 7.x-dev
Issue tags: +Bug Smash Initiative

Tested 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.