Tks!
Tks!
Using Hook or OOP you can customize the title of these menu local tasks tabs or add a new one
I don't know about you, but I found some titles too big or in some cases I want to show different titles, and so I looked for alternatives to achieve that and I found this way.
To contenxt, I got these two examples of tab menu, the first one is from
login form (Log in, Create new account, Password Recovery).
and this one is from administrative pages (Content, Comments and Files).
The first method is through hook_menu_local_tasks_alter, you basically should know the route name of the tab. This user.pass is the tab from password recovery. As you can see, you can add some static title or get dynamically as well.
On your custom module root, create the routing file: custom_module.routing.yml
In this example I'm using an Controller:
google.login:
path: '/user/login/glogin'
defaults:
_controller: '\Drupal\custom_module\Controller\GoogleTab::googleTabItem'
_title: 'Google Link'
requirements:
_permission: 'access content'
Also on you module root, create the links tasks file: custom_module.links.task.yml, here the key point is to know which base_route you want to add your new item to, in this case are: user.page
google.login:
route_name: google.login
base_route: user.page
title: 'Google Login'
options:
attributes:
class: ['google-tab-link']
And finally the Controller, really simple controller that redirect the user to /google.
You are free to build what you want here, enjoy!
On you module root, create the links tasks file: custom_module.links.task.yml, here the key point is to know which base_route you want to add your new item to, in this case are: user.page
google.login:
route_name: google.login
base_route: user.page
title: Google link
class: '\Drupal\custom_module\Plugin\Menu\LocalTask\GoogleTab'
On path: custom_module/src/Plugin/Menu/LocalTask creates you class, in this case: GoogleTab.php
Make sure that you class extends from LocalTaskDefault and now you can override the title as you wish.
That's it!!
Tks!
Join the conversation