Direkt zum Inhalt

Devbits

Kleine Code-Schnipsel aus unserem Alltag mit Drupal, PHP und DevOps: Problem, Lösung, Code.

23.10.2026 | Michael Ebert

Translate tab missing on custom config form

You have created a custom Drupal configuration form but no Translate tab appears when you access it.

my_module.my_form_configuration_tab:
  route_name: my_module.my_form_configuration
  title: Configuration
  base_route: my_module.my_form_configuration

Issue:

You have created a custom Drupal configuration form but no Translate tab appears when you access it.

The config_translation module automatically derives the Translate tab from the configuration mapper. However, Drupal only renders the local task (tab) navigation when there are at least two tabs on the same level. Since the Translate tab is the only local task available, Drupal does not display the tab navigation, causing the Translate tab to remain hidden.

Prerequisites:

You have the config_translations module enabled.

Solution:

Drupal Core solves the issue for settings forms by providing a default tab. We apply the same approach in our module by adding a default local task, which allows Drupal to render the tab navigation and display the Translate tab.

12.03.2026 | Peter Gerken

How to build a menu render array programmatically

This is a small but useful snippet for generating menu tree render arrays for any menu from a custom controller.

    $menu_name = 'my_custom_menu_machine_name';
  
    $menu_tree = \Drupal::menuTree();
    // Build the typical default set of menu tree parameters.
    $parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
    // Load the tree based on this set of parameters.
    $tree = $menu_tree->load($menu_name, $parameters);
    // Transform the tree using the manipulators you want.
    $manipulators = [
      // Only show links that are accessible for the current user.
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      // Use the default sorting of menu links.
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    
    $tree = $menu_tree->transform($tree, $manipulators);

    $menu = $menu_tree->build($tree);

     // Set theme for custom styling.
    $menu['#theme'] = 'my_custom_theme';

Issue:

Sometimes you might need to load and render a custom menu inside a controller – for example on a user dashboard – with access checking, default sorting, and a custom theme hook applied.

Solution:

This is a small but useful snippet for generating menu tree render arrays for any menu from a custom controller.

Just change $menu_name to the machine name of your menu.

Extra: For similar use cases, you might want to use the Drupal Twig Tweak module. You can also use the {{ drupal_menu('my_menu') }} function directly in your template.