0

How do I add the core user module links such as My account and Log out to another menu?

1 Answer 1

1

The My Account and Log Out links are defined in core/modules/user/user.links.menu.yml

user.page:
  title: 'My account'
  weight: -10
  route_name: user.page
  menu_name: account
user.logout:
  weight: 10
  menu_name: account
  class: Drupal\user\Plugin\Menu\LoginLogoutMenuLink

As you can see they are hardcoded to the account menu. With this in mind, really the best thing to do is simply place both menus next to each other on the Block Overview page. This works for probably 95% of use cases. Your CSS should be written in a way to support that. For the other 5%, you could go as far as to piggyback your own links in a custom module. If you were to do so, it would/could look something like this:

my_module.info.yml

type: module
name: 'My Module'
description: 'Copy user links.'
core_version_requirement: ^8.8 || ^9
package: 'User'
dependencies:
  - user:user

my_module.links.menu.yml

my_module.user_page:
  title: 'My account'
  weight: -10
  route_name: user.page
  menu_name: YOUR_MENU_ID
my_module.user_logout:
  weight: 10
  menu_name: YOUR_MENU_ID
  class: Drupal\user\Plugin\Menu\LoginLogoutMenuLink

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.