13.11.2025 | Mathias Grab

How to create local task links

my_module.links.task.yml
my_module.my_local_task_link:
  route_name: my_module.custom_route
  title: "Title"
  base_route: route_where.local_task.should_be_placed

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 propertyDescription
my_module.my_local_task_linkMachine name of the link.
route_nameThe route the link leads to.
titleHuman readable title of the link. Is shown on buttons or menu links.
base_routeBase route where the link is placed on.

 

my_module.routing.yml

yml propertyDescription
my_module.custom_routeMachine name of the registered route.
pathPath in URL.
defaultsDefault values for the upcoming properties.
_controllerNamespace of the controller that handles the logic when the route is accessed.
_titleHuman readable title of the route.
requirementsRequirements that must be met to access the route.
_permissionPermission that must be fulfilled to access the route. 

 

See the official Drupal documentation for further in-depth information.