1.callback mapping
2.visit permission
3.menu
include/menu.inc
menu.module
http://www.example.com/?q=cats
http://www.example.com/?q=node/3 they are same
how to create mymenu
mymenu.info
;$Id$
name="Mymenu Module"
descrption="Adds a menu to the navigation block"
varsion="$Name$"
mymenu.module
<?php
//$Id$
function mymenu_menu($may_cache){
$items=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'access'=>TRUE
);
}else{
$timestamp=format_date(time(),'small');
$items[]=array(
'title'=>t('stock quote at @time',array('@time'=>$timestamp)),
'path'=>'stockquote',
'callback'=>'mymenu_stock_quote',
'access'=>TRUE
);
}
return $items;
}
function mymenu_hello(){
return t('hello');
}
?>
/**
if you want to develop your own module. you should install devel.module
if you don't install it. you can delete the table cache_menu by hand
truncate table 'cache_menu'
and now we can change the menu and then via $websiteaddress?q=mymenu
it will show
HELLO good looking
if we use $webaddress?q=mymenu/Fred
HELLO Fred
*/
function mymenu_hello($name=NULL){
if(!isset($name)){
$name=t('good looking');
}
return t('HELLO @name!',array('@name'=>$name));
}
/**
you can define callback mapping in the hook function.you can load the same callback mapping
functional from differnt menu. and show the hidden infomation
*/
function mymenu_menu($may_cache){
$item=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'callback arguments'=>array(t('Hi!'),t('Ho!)),
'access'=>TRUE
);
}
}
function mymenu_hello($first,$second,$name=NULL){
drupal_set_message(t('first is %first',array('%first'=>$first)));
drupal_set_message(t('first is %second',array('%second'=>$second)));
if(!isset($name)){
$name=t('good looking');
}
return t('HELLO @name!',array('@name'=>$name));
}
/*how to add a sub_menu/
function mymenu_menu($may_cache){
$item=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'callback arguments'=>array(t('Hi!'),t('Ho!)),
'access'=>TRUE
);
$items[]= array(
'title'=>t('Fareware'),
'path'=>'mymenu/goodbye',
'callback'=>'mymenu_goodbye',
'access'=>TRUE
);
}
return $items;
}
/**
All above, we set the acces as true. how to manage it. and hook_perm
*/
function mymenu_perm(){
return array('receive greeting');
}
/*
if we set above 'access'=>user_access('receive greeting'). it mean that we only allow
receive greeting to visit this menu. in some conditions. we always meet. we don't need
to create the menu. but we should allocate the callback mapping
we always use MENU_CALL_BACK,MENU_LOCAL_TASK MENU_DEFAUTLT_LOCAL_TASK
we set node.module as a example
At local, this always occur at node,user,workflow
*/
node.module
$items[]= array(
'path'=>'rss.xml',
'title'=>t("RSS Feed'),
'callback=>'node_feed',
'access'=>user_access('access content'),
'type'=>MENU_CALLBACK
);
/*drupal can set two level menu defaultm */
function bookstore_menu($may_cache){
$items=array();
$items[]= array(
'title'=>t('Books'),
'path'=>'bookstore',
'callback'=>'bookstore_overview',
'type'=>MENU_CALLBACK,
'access'=>TRUE
);
$items[]= array(
'title'=>t('Books->List'),
'path'=>'bookstore/list',
'callback'=>'bookstore_list',
'type'=>MENU_DEFAULT_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
$items[]= array(
'title'=>t('Books->ADD'),
'path'=>'bookstore/ADD',
'callback'=>'bookstore_add',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('add bookstore')
);
$items[]= array(
'title'=>t('Books->List->shanghai'),
'path'=>'bookstore/list/shanghai',
'callback'=>'bookstore_list',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
$items[]= array(
'title'=>t('Books->List->BeiJing'),
'path'=>'bookstore/list/beijing',
'callback'=>'bookstore_list',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
return $items;
}
function bookstore_overview(){
$output=t('the following falvors are avaliable');
return $output;
}
/** let use devel for a menu example
use this way we don't need to change the core drupal code
*/
function mymodule_menu($may_cache){
$items=array();
if(!$may_cache&&module_exist('devel')){
$items[]=array(
'path'=>'devel/cache/clear',
'title'=>t('wrap cache clear'),
'callback'=>'mymodule_clear_cache',
'type'=>MENU_CALLBACK,
'access'=>user_access('access devel information')
//same as devel.module
);
}
}
function mymodule_clear_cache(){
drupal_set_message('we got called first');
devel_cache_clear();
}
//if we want to delete a menu
$items[]= array(
'path'=>'node/add',
'title'=>t('this should not shown up'),
'callback'=>'drupal_not_found',
'type'=>MENU_CALLBACK
);
/**
let do a interesting things. add a menu to delete all users in the exsit menu
if you want to display the menu at two place you can do like this
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK
*/
$items[]= array(
'path'=>'admin/user/deleteall',
'title'=>t('delete all users'),
'callback'=>'mymodule_deleteall_users',
'type'=>MENU_LOCAL_TASK,
'access'=>user_access('delete all users')
);
2.visit permission
3.menu
include/menu.inc
menu.module
http://www.example.com/?q=cats
http://www.example.com/?q=node/3 they are same
how to create mymenu
mymenu.info
;$Id$
name="Mymenu Module"
descrption="Adds a menu to the navigation block"
varsion="$Name$"
mymenu.module
<?php
//$Id$
function mymenu_menu($may_cache){
$items=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'access'=>TRUE
);
}else{
$timestamp=format_date(time(),'small');
$items[]=array(
'title'=>t('stock quote at @time',array('@time'=>$timestamp)),
'path'=>'stockquote',
'callback'=>'mymenu_stock_quote',
'access'=>TRUE
);
}
return $items;
}
function mymenu_hello(){
return t('hello');
}
?>
/**
if you want to develop your own module. you should install devel.module
if you don't install it. you can delete the table cache_menu by hand
truncate table 'cache_menu'
and now we can change the menu and then via $websiteaddress?q=mymenu
it will show
HELLO good looking
if we use $webaddress?q=mymenu/Fred
HELLO Fred
*/
function mymenu_hello($name=NULL){
if(!isset($name)){
$name=t('good looking');
}
return t('HELLO @name!',array('@name'=>$name));
}
/**
you can define callback mapping in the hook function.you can load the same callback mapping
functional from differnt menu. and show the hidden infomation
*/
function mymenu_menu($may_cache){
$item=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'callback arguments'=>array(t('Hi!'),t('Ho!)),
'access'=>TRUE
);
}
}
function mymenu_hello($first,$second,$name=NULL){
drupal_set_message(t('first is %first',array('%first'=>$first)));
drupal_set_message(t('first is %second',array('%second'=>$second)));
if(!isset($name)){
$name=t('good looking');
}
return t('HELLO @name!',array('@name'=>$name));
}
/*how to add a sub_menu/
function mymenu_menu($may_cache){
$item=array();
if($may_cache){
$items[]= array(
'title'=>t('Greeting'),
'path'=>'mymenu',
'callback'=>'mymenu_hello',
'callback arguments'=>array(t('Hi!'),t('Ho!)),
'access'=>TRUE
);
$items[]= array(
'title'=>t('Fareware'),
'path'=>'mymenu/goodbye',
'callback'=>'mymenu_goodbye',
'access'=>TRUE
);
}
return $items;
}
/**
All above, we set the acces as true. how to manage it. and hook_perm
*/
function mymenu_perm(){
return array('receive greeting');
}
/*
if we set above 'access'=>user_access('receive greeting'). it mean that we only allow
receive greeting to visit this menu. in some conditions. we always meet. we don't need
to create the menu. but we should allocate the callback mapping
we always use MENU_CALL_BACK,MENU_LOCAL_TASK MENU_DEFAUTLT_LOCAL_TASK
we set node.module as a example
At local, this always occur at node,user,workflow
*/
node.module
$items[]= array(
'path'=>'rss.xml',
'title'=>t("RSS Feed'),
'callback=>'node_feed',
'access'=>user_access('access content'),
'type'=>MENU_CALLBACK
);
/*drupal can set two level menu defaultm */
function bookstore_menu($may_cache){
$items=array();
$items[]= array(
'title'=>t('Books'),
'path'=>'bookstore',
'callback'=>'bookstore_overview',
'type'=>MENU_CALLBACK,
'access'=>TRUE
);
$items[]= array(
'title'=>t('Books->List'),
'path'=>'bookstore/list',
'callback'=>'bookstore_list',
'type'=>MENU_DEFAULT_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
$items[]= array(
'title'=>t('Books->ADD'),
'path'=>'bookstore/ADD',
'callback'=>'bookstore_add',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('add bookstore')
);
$items[]= array(
'title'=>t('Books->List->shanghai'),
'path'=>'bookstore/list/shanghai',
'callback'=>'bookstore_list',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
$items[]= array(
'title'=>t('Books->List->BeiJing'),
'path'=>'bookstore/list/beijing',
'callback'=>'bookstore_list',
'type'=>MENU_LOCL_CALLBACK,
'access'=>user_access('list bookstore')
);
return $items;
}
function bookstore_overview(){
$output=t('the following falvors are avaliable');
return $output;
}
/** let use devel for a menu example
use this way we don't need to change the core drupal code
*/
function mymodule_menu($may_cache){
$items=array();
if(!$may_cache&&module_exist('devel')){
$items[]=array(
'path'=>'devel/cache/clear',
'title'=>t('wrap cache clear'),
'callback'=>'mymodule_clear_cache',
'type'=>MENU_CALLBACK,
'access'=>user_access('access devel information')
//same as devel.module
);
}
}
function mymodule_clear_cache(){
drupal_set_message('we got called first');
devel_cache_clear();
}
//if we want to delete a menu
$items[]= array(
'path'=>'node/add',
'title'=>t('this should not shown up'),
'callback'=>'drupal_not_found',
'type'=>MENU_CALLBACK
);
/**
let do a interesting things. add a menu to delete all users in the exsit menu
if you want to display the menu at two place you can do like this
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK
*/
$items[]= array(
'path'=>'admin/user/deleteall',
'title'=>t('delete all users'),
'callback'=>'mymodule_deleteall_users',
'type'=>MENU_LOCAL_TASK,
'access'=>user_access('delete all users')
);