How to create local task links
Issue:
You want to create a local task link with a specific custom route.
Solution:
To create a local task link, define it in my_module.local.task.yml, optionally accompanied by my_module.routing.yml and MyCustomController.php. Alternatively, you can use existing routes, specifying route_name as the target of the link and base_route as the location where the link should appear.
Explanations for the most important properties in yml files
my.module.links.task.yml
| yml property | Description |
my_module.my_local_task_link | Machine name of the link. |
route_name | The route the link leads to. |
title | Human readable title of the link. Is shown on buttons or menu links. |
base_route | Base route where the link is placed on. |
my_module.routing.yml
| yml property | Description |
my_module.custom_route | Machine name of the registered route. |
path | Path in URL. |
defaults | Default values for the upcoming properties. |
_controller | Namespace of the controller that handles the logic when the route is accessed. |
_title | Human readable title of the route. |
requirements | Requirements that must be met to access the route. |
_permission | Permission that must be fulfilled to access the route. |
See the official Drupal documentation for further in-depth information.