menu有兩個來源,一是menu module的數據,另外一個是hook_menu,menu也決定了頁面的入口,是一個頁面的最基礎部分。php
title (string): Menu title
description (string): Menu description
page callback (string): 呈現頁面的函數
page arguments (array): page callback所需參數
access callback (boolean|string): 決定頁面的訪問權限,default: user_access
access arguments (array): access callback的參數
expanded (boolean): menu是否默認展開
type (int): menu的類型,drupal有固定的類型值
weight (int): 權重
file: 加載文件
https://api.drupal.org/api/dr...node
hook_menu應該返回一個函數,每一個key都表明一個URL,如user/%, node/%。key支持特殊的標識符,能夠把URL上的參數直接轉化爲一個對象,如user/%user, node/%node,它們會把URL上的ID值轉換爲user和node對象再提交到callback處理。api
drupal_get_form函數
user_is_logged_in
user_is_anonymouscode
MENU_CALLBACK : A hidden, internal callback, typically used for API calls.
MENU_DEFAULT_LOCAL_TASK : The "default" local task, which is initially active.
MENU_LOCAL_ACTION : An action specific to the parent, usually rendered as a link.
MENU_LOCAL_TASK : A task specific to the parent item, usually rendered as a tab.
MENU_NORMAL_ITEM : A "normal" menu item that's shown in menu and breadcrumbs.
MENU_SUGGESTED_ITEM : A normal menu item, hidden until enabled by an administrator. orm
https://api.drupal.org/api/dr...對象
$items['some'] = array( 'title' => 'some', 'menu_name' => 'main-menu', 'type' => MENU_NORMAL_ITEM, 'page callback' => 'any', 'access callback' => 'any' ); $items['some/home'] = array( 'title' => 'home page', 'type' => MENU_DEFAULT_LOCAL_TASK, // 若是含有sub menu,就必須有默認頁,它與some實際上是同一頁,但title會顯示在sub menu中 ); $items['some/other'] = array( 'title' => 'other page', 'type' => MENU_LOCAL_TASK, // 會在父級菜單下的TABS出現 'page callback' => 'any' );
$item = array( 'link_title' => 'Links', 'link_path' => 'links', 'menu_name' => 'main-menu', 'plid' => $plid, 'weight' => 2, ); $item['options']['attributes']['title'] = 'My links'; menu_link_save($item);