Score:0

How can I remove or rename tabs from the local tasks block?

de flag

local tasks

I'm using Drupal 9.2.6 with Group module and I want to remove some tabs from local tasks block and rename some of them.

I've created the module and placed above code with hook_menu_local_actions_alter and hook_menu_local_tasks_alter:

function mymodulename_menu_local_actions_alter(&$local_actions) {
   $local_actions['view.group_members.page_1']['title'] = t('Users');
}


function pacifica_menu_local_tasks_alter(&$data, $route_name) {
   unset($data['tabs'][0]['entity.group_content.collection']);
}

The route names where received from webprofiler.

Seems that code doesn't work - Members tab is not renamed to Users, and All entities tab is not hidden. And yes, I've cleared the caches.

Could someone, please, point me to the right direction in solving this?

leymannx avatar
ne flag
Does this answer your question? [How to alter local tasks menu titles?](https://drupal.stackexchange.com/questions/253280/how-to-alter-local-tasks-menu-titles)
leymannx avatar
ne flag
https://gorannikolovski.com/blog/dynamic-local-task-titles-drupal-8-9
Alex Sh avatar
de flag
Seems that my problem is that I can't find right variables for particular local task. How can I print all variables used in local tasks block?
leymannx avatar
ne flag
`composer install drupal/devel_kint_extras && drush -y en devel_kint_extras`, then go into your hook and put `ksm($variables);` , then `drush cr` and visit the site and it will print you a nicely formatted var_dump into the messages block which by default is placed on some region on the top of the site.
Alex Sh avatar
de flag
oh, man, thank you so much! I've used kint($data); and received the tabs array with all variables! then unset($data['tabs'][0]['group.content']); worked for me!
Alex Sh avatar
de flag
Maybe you could also help me with this: $data['tabs'][0]['views_view:view.group_nodes.page_1']['#link']['url'] = '/node/add/podcasts'; it doesn't work, how custom URL could be provided for existing tab?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.