'Change order and labels of local tasks in Drupal 9

I've got local tasks displayed as tabs on my users' profile page. Those local tasks are added by various modules. I need to change the order of those tabs, and change some of their labels.

I can't figure out how to do that.

I tried using the menu_tokens module to replace those tabs by a real, customizable menu, but unfortunately it's not working correctly in Drupal 9 yet and breaks the whole website. Maybe there's another way which I'm not aware of?



Solution 1:[1]

Use hook_local_tasks_alter hook inside your custom module. I've checked and it's still valid in d9.

Inside your module_name.module file place a function named according to the convention function module_name_local_tasks_alter(&$local_tasks) {

Place there a breakpoint or simply var dump the local tasks, you will see, how many local tasks tab goes through this function.

In the end you will find entity.user.canonical, just overwrite the item weight in similar manner:

$local_tasks['entity.user.canonical']['weight'] = -3;
$local_tasks['entity.user.edit_form']['weight'] = -2;

Source: https://codimth.com/blog/web/drupal/how-override-local-task-drupal-8

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cssBlaster21895