0

I just want to remove a secondary menu local task from a preprocess function such as

function mymodule_preprocess_menu_local_tasks(&$vars, $hooks) { 
    $vars['secondary'] = '';
}

I'm using D7, sky theme for front-end and seven theme for admin. The above code works in seven but not in sky.

The sky theme page.tpl.php has a variable $secondary_local_tasks which I might be able to remove from hook_preprocess_page(). I also tried this :

function mymodule_preprocess_page(&$vars, $hooks) { 
    $vars['secondary_local_tasks'] = '';
    unset($vars['tabs']['#secondary']);
}

My hook is invoked correctly, but the secondary local task is still rendered to the template. Where local tasks are prepared to be rendered after my hook ?

3 Answers 3

1

Finally, I've done with hook_process_page() and removed the variable secondary_local_tasks upon logged-in user role before rendering to the template.

function mymodule_process_page(&$vars, $hooks){
    global $user;
    if(array_key_exists(6, $user->roles) && arg(0) == 'user' && arg(2) == 'edit'){
        $vars['tabs']['#secondary'] = array();
        if(isset($vars['secondary_local_tasks'])){
            $vars['secondary_local_tasks'] = array();
        }
    }
}

I have also tried this from hook_preprocess_page(), but it did not work on the sky theme.
Related question is here : Profile2 and profile fields by user role

0
1

Or use: hook_menu_local_tasks_alter()

1
  • This is the really right answer. Commented Apr 23, 2014 at 12:13
0

You could use hook_menu_alter to remove any menu entry. This would be completely indipendent of the theme.

Just implement hook_menu_alter in a custom module and look at the given menu items with a dubugger or dpm(). Then do something like this:

unset($items['menu/item/to/delete'];
1
  • 1
    Thanks, but I will remove the tab dynamically upon logged-in user role. hook_menu_alter does not run on every page load.
    – Sithu
    Commented Jan 31, 2012 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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