1

I've tried with my custom module to implement hook_menu_local_tasks_alter, but I'm not sure how can I edit specific tab.

Here's my example code:

function my_module_menu_local_tasks_alter(&$data, $router_item, $root_path) {   
  $data['tabs']['0']['output']['0']['#access'] = FALSE; 
  //krumo($data);
}

With this code I can hide the first tab, but that does on all pages.

When I'm using hook_form_alter and with krumo(form_id) I can see what form is and I'm using switch statement to edit specific form. Is it possible to do this or something similar with tabs?

I'm not using CSS in this case, because I like to change the name of the tabs on specific pages too.

3
  • What tab are you trying to hide (what's the label, what module provides it, etc)? You should be able to find current page context in $router_item
    – Clive
    Sep 26, 2013 at 13:08
  • I want to hide "View" tab that appears on created node. Later I want to rename one specific tab on user page. I've checked with $router_item and I saw that the specific path is node/%, but when I use switch statement with case 'node/%': it didn't worked like that. Sep 26, 2013 at 13:24
  • Might be easier to implement hook_menu_alter() and use $items['node/%/view']['type'] = MENU_NORMAL_ITEM; (or something like that) instead
    – Clive
    Sep 26, 2013 at 13:26

1 Answer 1

3

You can use hook_menu_local_tasks_alter() in your template.php file for your theme or .module file in module like below:

function YOURTHEME_menu_local_tasks_alter(&$data, $router_item, $root_path) {

  foreach ($data['tabs'] as $key1 => $tabs) {
    foreach ($tabs['output'] as $key2 => $item) {

      if ($item['#link']['path'] == 'node/%/edit' || $item['#link']['path'] == 'user/%/edit') {
        $data['tabs'][$key1]['output'][$key2]['#link']['localized_options']['attributes']['class'][]  = 'CLASS_NAME_HERE';
      }
      else if ($item['#link']['path'] == 'node/%/delete') {
        $data['tabs'][$key1]['output'][$key2]['#link']['localized_options']['attributes']['class'][]  = 'CLASS_NAME_HERE';

      }
      else if ($data['tabs'][$key1]['output'][$key2]['#link']['title'] == 'View') {
        $data['tabs'][$key1]['output'][$key2]['#link']['localized_options']['attributes']['class'][]  = 'CLASS_NAME_HERE'; 

      }
      else if ($item['#link']['path'] == 'node/%/revisions') {
        $data['tabs'][$key1]['output'][$key2]['#link']['localized_options']['attributes']['class'][]  = 'CLASS_NAME_HERE';

      }

    }
  }
}

Hope this will help.

Your Answer

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

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