Hoping someone can point me in the right direction. I need to remove a tab from the Local Tasks bar. This tab is created via a custom module. Currently I'm using hook_menu_local_tasks_alter() to remove the tab from a user with a specific role. Here's the weird part: if I go to unset the tab without checking for the users role, the tab disappears and the rest of the tabs remain. When I go to check if the user's role is in one of the allowed roles for this tab and it returns false, the ENTIRE tab disappears. Here's my code:
function content_usage_menu_local_tasks_alter(&$data, $route_name) {
$allowed_roles = ["administrator", "author", "editor", "admin"];
$roles = \Drupal::currentUser()->getRoles();
if (empty(array_intersect($allowed_roles, $roles))) {
unset($data['tabs'][0]['node_usage.form']);
}
}
Any ideas why this would be happening? Am I missing something?
Thanks.
Comments
=-=
may want to look @
https://www.drupal.org/project/tab_manager
https://www.drupal.org/project/tabtamer
Thank you!
I'm going to check these two out. This might just be what I needed. Thank you.
Same issue arises with these modules
I have no idea what's going on. I installed and tested both modules. As soon as I hide the one tab, the ENTIRE TAB disappears.
I'm seriously at a loss.
Number of Tabs is The Cause
I just went through the code with X-debug and after digging deeper, I found a core file LocalTasksBlock.php. Apparently if there is only one tab left, it will NOT display. And I believe this is my issue since only one tab would be left after removing the other one.
Actually Correct..even I am
Actually Correct..even I am facing the same issue-if there is one tab, then tabs section don't appear at all.