簡體   English   中英

Drupal 7-通過代碼創建多個自定義菜單項的最合適方法

[英]Drupal 7 - Most Appropriate Way to Create Multiple Custom Menu Items Via Code

我目前有一個使用以下代碼創建的自定義菜單項,它的效果很好:

function myModule_menu(){
    $items = array();

    $items['myModule'] = array(
        'title' => 'Business Owner Dashboard',
        'page callback' => '_custom_page',
        'access arguments' => array('use_business_dashboard'),
        'type' => MENU_NORMAL_ITEM,
    );

    return $items;
}

我要為多個角色創建多個菜單項,而不僅僅是一個。 我假設我可以某種方式使用開關盒,但是我不確定如何使用該開關盒,並且找不到有關該主題的任何文檔。

為了澄清起見,我想使用相同的myModule_menu()函數來設置“企業主儀表板”以及另一個菜單項“ Referrals”,並使用不同的“頁面回調”,“訪問參數”等。這個話題將不勝感激!

添加更多菜單項非常簡單-只需在$items數組中定義另一個元素:

function myModule_menu() {
    $items['admin/business'] = array(
        'title' => 'Business',
        'description' => 'Business.',
        'page callback' => '_administer_business',
        'access arguments' => array('administer business'),
        'file' => 'business.admin.inc', //if the page callback function is in another file
    );
    if (referrals_allowed) {
        $items['admin/referrals'] = array(
            'title' => 'Referals',
            'description' => 'Referrals.',
            'page callback' => '_administer_referrals',
            'access arguments' => array('administer referrals'),
            'file' => 'referrals.admin.inc', //if the page callback function is in another file
        );
    }

    return $items;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM