drupal hook_menu_alter() for adding tabs

Posted by EricP on Stack Overflow See other posts from Stack Overflow or by EricP
Published on 2010-05-20T18:49:17Z Indexed on 2010/05/20 20:10 UTC
Read the original article Hit count: 190

Filed under:
|
|
|
|

I want to add some tabs in the "node/%/edit" page from my module called "cssswitch". When I click "Rebuild Menus", the two new tabs are displayed, but they are displayed for ALL nodes when editing them, not just for the node "cssswitch". I want these new tabs to be displayed only when editing node of type "cssswitch".

The other problem is when I clear all cache, the tabs completely dissapear from all edit pages. Below is the code I wrote.

    function cssswitch_menu_alter(&$items) {

        $node = menu_get_object();
        //print_r($node);
        //echo $node->type; //exit();
        if ($node->type == 'cssswitch') {

            $items['node/%/edit/schedulenew'] = array(
                'title' => 'Schedule1',
                'access callback'=>'user_access',
                'access arguments'=>array('view cssswitch'),
                'page callback' => 'cssswitch_schedule',
                'page arguments' => array(1),
                'type' => MENU_LOCAL_TASK,
                'weight'=>4,
            );

            $items['node/%/edit/schedulenew2'] = array(
                'title' => 'Schedule2',
                'access callback'=>'user_access',
                'access arguments'=>array('view cssswitch'),
                'page callback' => 'cssswitch_test2',
                'page arguments' => array(1),
                'type' => MENU_LOCAL_TASK,
                'weight'=>3,
            );  


        }

    }

function cssswitch_test(){
    return 'test';
}

function cssswitch_test2(){
    return 'test2';
}

Thanks for any help.

© Stack Overflow or respective owner

Related posts about drupal

Related posts about hook