In a custom module (association), I ceated views that are accessible thru tabs:
enter image description here The paths are defined in the views;

  • Adhérents et personnes -> /association (this one is also defined as a menu item)
  • Adhérents -> /association/members
  • Personnes -> /association/persons

I'd like to add /admin/people as a fourth tab.
How can I do that?


In a custom module (mymodule), create a mymodule.links.task.yml file, and add the following:

mymodule.admin_people: route_name: entity.user.collection base_route: route.of.your.custom.menu title: 'Tab text goes here'

Here's what each part does:

mymodule.admin_people Is the identifier of your menu tab item (the file being *.links.task.yml means its the menutab file)

route_name is the route the tab points to, and entity.user.collection is the route that corresponds to /admin/people .

base route displays your tab on the specified route. To find the route for your view, download the Devel module, turn it on, and go to "Routes info" to get your route. Usually a view is of the format view.[view_machine_name].[view_display_id], i.e. view.myview.page_1 . Check the "advanced" section of your view's management page for the display ID.

title is the text that will go into the tab.

|improve this answer|||||
  • also note, *.links.action.yml specifies action links i.e. add buttons you tend to see of some admin pages, and *.links.menu.yml creates menu items. Each one uses slightly different YAML, so look at other modules for clues. – Mike Nolan Jan 22 at 18:08
  • It works! capture1 but when I go to /admin/people, I get my custom tabs miwed with standard Drupal tabs: capture2 How to avoid this? – gbmapo Jan 23 at 8:13
  • And, by the way, how can I get the weight of each tab? – gbmapo Jan 23 at 8:16
  • For your own tabs, you can set a 'weight' property. For seeing other tabs, take a look at drupal.org/docs/8/api/menu-api/… , which explains how to set up derivers, among other interesting tricks. – Mike Nolan Jan 26 at 14:37

Finally and because of the side effect of the solution proposed by Mike Nolan (see capture2 in my comment), I made it that way:

function association_menu_local_tasks_alter(&$data, $route_name) {

  $oCurrentUser = \Drupal::currentUser();
  switch ($route_name) {
    case 'view.association_members_and_persons.page_1':
    case 'view.association_members.page_1':
    case 'view.association_persons.page_1':
      if ($oCurrentUser->hasPermission('administer users')) {
        $data['tabs'][0]['association.people'] = [
          '#theme' => 'menu_local_task',
          '#link' => [
            'title' => t('Users'),
            'url' => Url::fromRoute('entity.user.collection'),
          '#weight' => 4,
|improve this answer|||||

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.