Pages

Wednesday, February 16, 2011

Drupal Module - Secondary Menu Tab

This code below shows how it's easy to build menu system in drupal using drupal hook_menu.
This menu item lies in the navigation menu block, while the menu tab (primary menu tab) lies on top of page and the secondary menu tabs below it.
This is the info file, menu_learning.info
name = Learning Menu
description = Learning Menu In Drupal
core = 7.x
version = alpha
package = Learning

This is the module file, menu_learning_info
<?php

/**
 * Implements hook_menu()
 */
function menu_learning_menu(){
    $items = array();
    $i = 2;
    
    /**
     * The main menu that available of the navigation block
     */
    $items['learning/menu'] = array(
        'title' => 'Menu Learning',
        'description' => 'Menu Learning In Drupal Bro',
        'page callback' => 'hey',
        'access callback' => TRUE,
    );
    
    /**
     * Primary Default Menu Tab
     * No need for page callback because inherit from the main
     */
    $items['learning/menu/default'] = array(
        'title' => 'Default Menu',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'page callback' => 'hello',
        'access callback' => TRUE,
        'weight' => 1,
    );  

    /**
     * Primary menu tab
     */   
    foreach(array('agnes'=>'Agnes Monica','gaga'=>'Lady Gaga', 
                  'luna'=>'Luna Maya') as $key => $value){
        $items['learning/menu/'.$key.''] = array(
            'title' => $value,
            'type' => MENU_LOCAL_TASK,
            'page callback' => 'show_page',
            'page arguments' => array($value),
            'access callback' => TRUE,
            'weight' => $i++,
        );   
    }

    /**
     * Secondary default menu tab
     */       
    $items['learning/menu/default/first'] = array(
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'title' => t('Default Secondary Tab'),
    );
    
    /**
     * The next secondary menu tabs
     */
    $items['learning/menu/default/second'] = array(
        'type' => MENU_LOCAL_TASK,
        'title' => 'Second Tab',
        'page callback' => 'second',
        'access callback' => TRUE,
    );

    /**
     * The next secondary menu tabs
     */       
    $items['learning/menu/default/third'] = array(
        'type' => MENU_LOCAL_TASK,
        'title' => 'Third Tab',
        'page callback' => 'third',
        'access callback' => TRUE,
    );
   
    return $items;
}

function hey(){
    return t('Holla from indonesia is like for you all here and we wiil do  this one');
}

function show_page($msg){
    return "Hello From $msg! <br/>When you are here, "
          ."we all can do more for this one."
          ."So in the next future, we hope you all get"
          ."want you want.<br/>Thank You.";
}

function second(){
    return t('Second sentence for you');
}

function third(){
    return t('Third argument supplied');
}

No comments:

Post a Comment