Like a function to debug a page or something. Want to add a link via links.yml but can't get the menu 'parent' name enter image description here


What you're wanting is the route name, not menu parent name (it's changed since D7). You can retrieve a route name a couple of different ways:

  • Use Url::getRouteName() to look up your current route:

    $path = \Drupal::service('path.current')->getPath();
    $url = \Drupal\Core\Url::fromUri( 'internal:' . $path );

  • Use the Webprofiler module to look up the current route as you're viewing it.

  • Look up URL patterns in the router DB table.

To see how the core node module does it for the tasks in your screenshot look at core/modules/node/node.links.task.yml

For further information on adding local tasks to routes, read Providing module-defined local tasks.


You can use hook_menu_local_tasks() or hook_menu_local_task(). It is primary Tabs.

function mymodule_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  foreach ($data['tabs'] as $key1 => $tabs) {
    foreach ($tabs['output'] as $key2 => $item) {
      // Conditionally change the link title.
      if ($item['#link']['path'] == 'some/path/here') {
        $data['tabs'][$key1]['output'][$key2]['#link']['title'] = 'New Title';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.