3

In earlier versions of Drupal, there were categories of users which showed up as tabs on the user (profile) edit page, located at /user/{user}/edit. How can we define new tabs on this page in Drupal 8?

4

Tabs can be added to the user edit page as follows:

1) Define the route(s) for your tab(s) in [MODULE].routing.yml as normal:

[MODULE].something.user_defaults:
  path: '/user/{user}/edit/something'
  defaults:
    _controller: '\Drupal\[MODULE]\Controller\SomeController::someSettingsTab'
    _title: 'Some Settings'
  requirements:
    _permission: 'some permission'
    user: \d+
  options:
    parameters:
      user:
        type: entity:user

2) In [MODULE].links.tasks.yml, add your tab(s) as you would primary tabs, except rather than using base_route, use parent_id, and set it to (somewhat unintuitively) the user edit form tab key, which is defined in user.links.task.yml as entity.user.edit_form (same as the route name):

[MOUDLE].something.user_defaults:
  route_name: [MODULE].something.user_defaults
  parent_id: entity.user.edit_form
  title: Some Title
  weight: 10

3) You also need to define a tab for the user to switch back to, as tabs are only rendered if there are more than two tabs. In this case, we want to add a tab for the user edit form, using the user edit form route, again using the user edit form tab key:

[MODULE].entity.user.edit_form:
  route_name: entity.user.edit_form
  parent_id: entity.user.edit_form
  title: Profile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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