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.

Weitere DevBits

13.11.2025 | Peter Majmesku

Autowire services with the Autowire attribute in Drupal

Example.php
<?php

declare(strict_types=1);

namespace Drupal\my_module;

use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class Example {

  public function __construct(
    #[Autowire(service: 'current_user')]
    private readonly AccountInterface $currentUser,
  ) {
  }

  public function getCurrentUser(): AccountInterface {
    return $this->currentUser;
  }

}

my_module.services.yml
services:
  my_module.example:
    class: Drupal\my_module\Service\Example
    autowire: true
  Drupal\my_module\Service\Example: '@my_module.example'

php
services
yml / yaml
02.04.2026 | Michael Ebert

Set a custom theme to be used by Symfony Mailer

symfony_mailer.mailer_policy._.yml
configuration:
  email_theme:
    theme: my_custom_theme

yml / yaml
symfony
mail
themes